Sources for Matthijs Hollemans' WebWatch app, I don't use it (anyone actually using @beats ?) but it's quite cute and could serve as nice sample code. And it's under MIT licence.

Oddly this is version 1.5 while bebits still has 1.4 :)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25440 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-05-11 00:02:26 +00:00
parent 745c6cce89
commit 1d7c2d4adc
7 changed files with 520 additions and 0 deletions

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 1999-2003 Matthijs Hollemans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <Roster.h>
#include <Deskbar.h>
#include "WatchApp.h"
#include "WatchView.h"
////////////////////////////////////////////////////////////////////////////////
BView* instantiate_deskbar_item()
{
return new WatchView;
}
////////////////////////////////////////////////////////////////////////////////
WatchApp::WatchApp() : BApplication(APP_SIGNATURE)
{
// Here we tell the Deskbar that we want to add a new replicant, and
// where it can find this replicant (in our app). Because we only run
// less than a second, there is no need for our title to appear inside
// the Deskbar. Therefore, the application flags inside our resource
// file should be set to B_BACKGROUND_APP.
BDeskbar deskbar;
if (!deskbar.HasItem(DESKBAR_ITEM_NAME))
{
entry_ref ref;
be_roster->FindApp(APP_SIGNATURE, &ref);
deskbar.AddItem(&ref);
}
PostMessage(B_QUIT_REQUESTED);
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
WatchApp watchApp;
watchApp.Run();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 1999-2003 Matthijs Hollemans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef WATCHAPP_H
#define WATCHAPP_H
#include <Application.h>
#define VERSION "1.5"
#define APP_SIGNATURE "application/x-vnd.mahlzeit.webwatch"
#define DESKBAR_ITEM_NAME "WebWatch2"
#define REPLICANT_CLASS "WatchView"
class WatchApp : public BApplication
{
public:
WatchApp();
};
extern "C" _EXPORT BView* instantiate_deskbar_item();
#endif // WATCHAPP_H

View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 1999-2003 Matthijs Hollemans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <Alert.h>
#include <Deskbar.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <String.h>
#include <stdio.h>
#include "WatchApp.h"
#include "WatchView.h"
const rgb_color COLOR_FOREGROUND = { 0, 0, 0 };
////////////////////////////////////////////////////////////////////////////////
WatchView::WatchView()
: BView(BRect(0, 0, 1, 1), 0, 0, 0)
{
// Do nothing.
}
////////////////////////////////////////////////////////////////////////////////
WatchView::WatchView(BMessage* message)
: BView(
BRect(0, 0, 15, 15), DESKBAR_ITEM_NAME, B_FOLLOW_NONE,
B_WILL_DRAW | B_PULSE_NEEDED)
{
oldTime = 0;
//SetFont(be_bold_font);
SetFont(be_plain_font);
// Calculate the maximum width for our replicant. Note that the Deskbar
// accepts replicants that are wider than 16 pixels, but not replicants
// that are higher than 16 pixels.
float width = StringWidth("@999") + 4;
ResizeTo(width, 15);
SetViewColor(B_TRANSPARENT_COLOR);
}
////////////////////////////////////////////////////////////////////////////////
__declspec(dllexport) WatchView* WatchView::Instantiate(BMessage* archive)
{
if (validate_instantiation(archive, REPLICANT_CLASS))
{
return new WatchView(archive);
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
status_t WatchView::Archive(BMessage* archive, bool deep) const
{
super::Archive(archive, deep);
archive->AddString("add_on", APP_SIGNATURE);
archive->AddString("class", REPLICANT_CLASS);
return B_OK;
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::Draw(BRect updateRect)
{
super::Draw(updateRect);
char string[5];
sprintf(string, "@%03ld", GetInternetTime());
font_height height; // center the text horizontally
GetFontHeight(&height); // and vertically in the Deskbar
BRect rect = Bounds();
float width = StringWidth(string);
float x = 1 + (rect.Width() - width)/2;
float y = height.ascent
+ (rect.Height() - (height.ascent + height.descent))/2;
SetHighColor(Parent()->ViewColor());
FillRect(updateRect);
SetLowColor(Parent()->ViewColor());
SetHighColor(COLOR_FOREGROUND);
SetDrawingMode(B_OP_OVER);
DrawString(string, BPoint(x, y));
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::MouseDown(BPoint point)
{
BPopUpMenu* menu = new BPopUpMenu("WatchView", false, false);
menu->AddItem(new BMenuItem(
"About" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)));
menu->AddItem(new BMenuItem(
"Quit", new BMessage(B_QUIT_REQUESTED)));
menu->SetTargetForItems(this);
ConvertToScreen(&point);
menu->Go(point, true, false, true);
delete menu;
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case B_ABOUT_REQUESTED: OnAboutRequested(); break;
case B_QUIT_REQUESTED: OnQuitRequested(); break;
default: super::MessageReceived(msg); break;
}
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::OnAboutRequested()
{
(new BAlert(
NULL,
"WebWatch " VERSION
"\nAn Internet Time clock for your Deskbar\n\n"
"Created by Matthijs Hollemans\n"
"mahlzeit@users.sourceforge.net\n\n"
"Thanks to Jason Parks for his help.\n",
"Okay"))->Go(NULL);
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::OnQuitRequested()
{
// According to the Be Book, we are not allowed to do this
// since we're a view that's sitting on the Deskbar's shelf.
// But it works just fine for me, and I see no other way to
// make a Deskbar replicant quit itself.
BDeskbar deskbar;
deskbar.RemoveItem(DESKBAR_ITEM_NAME);
}
////////////////////////////////////////////////////////////////////////////////
void WatchView::Pulse()
{
int32 currentTime = GetInternetTime();
if (oldTime != currentTime)
{
oldTime = currentTime;
Invalidate();
}
}
////////////////////////////////////////////////////////////////////////////////
int32 WatchView::GetInternetTime()
{
// First we get the current time as the number of seconds since
// 1 January 1970 GMT and add an hour's worth of seconds to adjust
// for the Biel Mean Time (BMT). Then we get the number of seconds
// that have passed today, and divide it with the length of a beat
// to get the number of elapsed beats.
return (int32) (((real_time_clock() + 3600) % 86400) / 86.4);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 1999-2003 Matthijs Hollemans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef WATCHVIEW_H
#define WATCHVIEW_H
#include <View.h>
class WatchView : public BView
{
public:
// This constructor is used by the WatchApp class to install the
// WebWatch replicant into the Deskbar.
WatchView();
// This constructor is used to "rehydrate" the archived WatchView
// object after the Deskbar (or any other BShelf) has received it.
WatchView(BMessage* message);
// Called by the Deskbar's shelf after it has received the message
// that contains our replicant. (To enable the Deskbar to find this
// function, we export it from the executable.)
static WatchView* Instantiate(BMessage* archive);
// Archives the data that we need in order to instantiate ourselves.
virtual status_t Archive(BMessage* archive, bool deep = true) const;
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
virtual void MessageReceived(BMessage* message);
// Periodically checks whether the Internet Time has changed, and tells
// the view to redraw itself. The time between these checks depends on
// the pulse rate of the Deskbar window. By default the pulse rate is 500
// milliseconds, which is fine for our purposes. Note that other Deskbar
// replicants could possibly change the pulse rate of the Deskbar window.
virtual void Pulse();
private:
typedef BView super;
void OnAboutRequested();
void OnQuitRequested();
// Calculates the current Internet Time.
int32 GetInternetTime();
// The Internet Time from the last call to Pulse().
int32 oldTime;
};
#endif // WATCHVIEW_H

Binary file not shown.

View File

@ -0,0 +1,24 @@
# Makefile for WebWatch
NAME= WebWatch
TYPE= APP
SRCS= WatchApp.cpp WatchView.cpp
RSRCS= WebWatch.rsrc
LIBS= be
LIBPATHS=
SYSTEM_INCLUDE_PATHS =
LOCAL_INCLUDE_PATHS =
OPTIMIZE= FULL
DEFINES=
WARNINGS = ALL
SYMBOLS = FALSE
DEBUGGER = FALSE
COMPILER_FLAGS =
LINKER_FLAGS =
include /boot/develop/etc/makefile-engine
release:
@strip $(OBJ_DIR)/$(NAME)
@xres -o $(OBJ_DIR)/$(NAME) $(RSRCS)
@mimeset -f $(OBJ_DIR)/$(NAME)

View File

@ -0,0 +1,117 @@
<HTML>
<HEAD>
<TITLE>WebWatch</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1>WebWatch 1.5</H1>
<P>Released on Thursday, 13 February 2003<BR>
Created by <A HREF="mailto:mahlzeit@users.sourceforge.net">Matthijs
Hollemans</A></P>
<H3>What is it</H3>
<P>WebWatch is an unofficial port of Swatch's Internet Time utility for BeOS
R5 or higher that runs inside the Deskbar.</P>
<P>Someone at Swatch (you know, the company that makes the watches) came up
with an idea for a universal time format that eliminates time zones and
geographical borders. The idea is very simple: time is no longer measured in
hours, minutes, and seconds, but in "beats." A single day consists of 1000
beats, so each beat corresponds to 1 minute and 26.4 seconds.</P>
<P>This "Internet Time" is the same all over the world, because it is measured
relatively to something called the Biel Mean Time (BMT), a new meridian that
lies in Switzerland. A day in Internet Time begins at midnight BMT, or @000
Swatch Beats, 12 noon is equivalent to @500 beats, and so on. So if it's @812
at my place, it's also 812 beats at yours and everyone else's.</P>
<P>Please check out the <A HREF="http://www.swatch.com">Swatch website</A>
for more information.</P>
<H3>How to use it</H3>
<P>Simply double-click the WebWatch icon to install WebWatch into the Deskbar.
To get rid of it, right-click <CODE>WebWatch</CODE> in the Deskbar and select
the <CODE>Quit</CODE> option from the pop-up menu.</P>
<H3>Legal stuff</H3>
<P>This version of WebWatch is open source and may be distributed under the
terms of the MIT license. Note that the author is in no way affiliated with
Swatch, and fully respects their copyrights and trademarks.</P>
<P>Copyright (c) 1999-2003 Matthijs Hollemans</P>
<P>Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:</P>
<P>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</P>
<P>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.</P>
<H3>History</H3>
<P><I>Version 1.5 (Thursday, 13 February 2003)</I></P>
<UL>
<LI>Cleaned up the source code.</LI>
<LI>Now uses the plain font, not the bold font.</LI>
</UL>
<P><I>Version 1.4 (Saturday, 9 December 2000)</I></P>
<UL>
<LI>With certain fonts, WebWatch didn't always fit in the Deskbar.</LI>
</UL>
<P><I>Version 1.3 (Sunday, 26 November 2000)</I></P>
<UL>
<LI>The time is now written using a bold font, making it better readable.</LI>
<LI>Thanks to Jason Parks for turning WebWatch into a real Deskbar add-on.
Because of this, WebWatch no longer needs to be installed in the
UserBootscript; the Deskbar starts it automatically. This also means that
WebWatch is now BeOS R5 or higher only.</LI>
</UL>
<P><I>Version 1.2 (Tuesday, 26 September 2000)</I></P>
<UL>
<LI>Finally fixed a long-standing bug with WebWatch's background color. Now it
uses the same color as the Deskbar.</LI>
</UL>
<P><I>Version 1.1 (Tuesday, 28 March 2000)</I></P>
<UL>
<LI>New release for BeOS R5. Older versions of WebWatch came with source
code only, which was automatically compiled during installation. However,
because of header file changes between R5 and older versions of the BeOS,
and because the free version of BeOS R5 doesn't necessarily include
development tools, WebWatch 1.1 is already compiled. This means that it
only runs on the Intel platform, since I don't have a PowerPC machine.</LI>
</UL>
<P><I>Version 1.0 (Saturday, 14 August 1999)</I></P>
<UL>
<LI>First version.</LI>
</UL>
</BODY>
</HTML>