From 1d7c2d4adc6605ef391186c33dddbc0b40076186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sun, 11 May 2008 00:02:26 +0000 Subject: [PATCH] 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 --- src/apps/webwatch/WatchApp.cpp | 66 +++++++++++ src/apps/webwatch/WatchApp.h | 41 +++++++ src/apps/webwatch/WatchView.cpp | 199 ++++++++++++++++++++++++++++++++ src/apps/webwatch/WatchView.h | 73 ++++++++++++ src/apps/webwatch/WebWatch.rsrc | Bin 0 -> 2863 bytes src/apps/webwatch/makefile | 24 ++++ src/apps/webwatch/readme.html | 117 +++++++++++++++++++ 7 files changed, 520 insertions(+) create mode 100644 src/apps/webwatch/WatchApp.cpp create mode 100644 src/apps/webwatch/WatchApp.h create mode 100644 src/apps/webwatch/WatchView.cpp create mode 100644 src/apps/webwatch/WatchView.h create mode 100644 src/apps/webwatch/WebWatch.rsrc create mode 100644 src/apps/webwatch/makefile create mode 100644 src/apps/webwatch/readme.html diff --git a/src/apps/webwatch/WatchApp.cpp b/src/apps/webwatch/WatchApp.cpp new file mode 100644 index 0000000000..fad4681b3b --- /dev/null +++ b/src/apps/webwatch/WatchApp.cpp @@ -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 +#include + +#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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/apps/webwatch/WatchApp.h b/src/apps/webwatch/WatchApp.h new file mode 100644 index 0000000000..e3753ea2a4 --- /dev/null +++ b/src/apps/webwatch/WatchApp.h @@ -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 + +#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 diff --git a/src/apps/webwatch/WatchView.cpp b/src/apps/webwatch/WatchView.cpp new file mode 100644 index 0000000000..64cca9779b --- /dev/null +++ b/src/apps/webwatch/WatchView.cpp @@ -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 +#include +#include +#include +#include +#include + +#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); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/apps/webwatch/WatchView.h b/src/apps/webwatch/WatchView.h new file mode 100644 index 0000000000..425b027331 --- /dev/null +++ b/src/apps/webwatch/WatchView.h @@ -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 + +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 diff --git a/src/apps/webwatch/WebWatch.rsrc b/src/apps/webwatch/WebWatch.rsrc new file mode 100644 index 0000000000000000000000000000000000000000..29f84017fdd7bfb5bf3e1b54af7d948f963775dd GIT binary patch literal 2863 zcmWFvW?*0t@ONPWQZ69O1|-M;AiWGgy)T&|W@Ioz*dXEmKmZb_1-p-nfnhGtV37H1 z*cljvAl5MK1F}`1>_w z(8=EoShWhl>N!S+#DapH%;dz9%=|q43f;226usQUjGU^}%o4rw)THvnlH?2qpbiFB zh{bT)QK2Bes6-(@O(7VpNWn9&B(*3nwL~E#GdC5g7!O6Memq8xN{!GE0JY5A-GhBW z=@o)2(J3zTO70Qo#i(*OVf literal 0 HcmV?d00001 diff --git a/src/apps/webwatch/makefile b/src/apps/webwatch/makefile new file mode 100644 index 0000000000..d039917c14 --- /dev/null +++ b/src/apps/webwatch/makefile @@ -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) diff --git a/src/apps/webwatch/readme.html b/src/apps/webwatch/readme.html new file mode 100644 index 0000000000..4f4f2e91a8 --- /dev/null +++ b/src/apps/webwatch/readme.html @@ -0,0 +1,117 @@ + + + +WebWatch + + + + +

WebWatch 1.5

+ +

Released on Thursday, 13 February 2003
+Created by Matthijs +Hollemans

+ +

What is it

+ +

WebWatch is an unofficial port of Swatch's Internet Time utility for BeOS +R5 or higher that runs inside the Deskbar.

+ +

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.

+ +

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.

+ +

Please check out the Swatch website +for more information.

+ +

How to use it

+ +

Simply double-click the WebWatch icon to install WebWatch into the Deskbar. +To get rid of it, right-click WebWatch in the Deskbar and select +the Quit option from the pop-up menu.

+ +

Legal stuff

+ +

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.

+ +

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.

+ +

History

+ +

Version 1.5 (Thursday, 13 February 2003)

+ +
    +
  • Cleaned up the source code.
  • +
  • Now uses the plain font, not the bold font.
  • +
+ +

Version 1.4 (Saturday, 9 December 2000)

+ +
    +
  • With certain fonts, WebWatch didn't always fit in the Deskbar.
  • +
+ +

Version 1.3 (Sunday, 26 November 2000)

+ +
    +
  • The time is now written using a bold font, making it better readable.
  • +
  • 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.
  • +
+ +

Version 1.2 (Tuesday, 26 September 2000)

+ +
    +
  • Finally fixed a long-standing bug with WebWatch's background color. Now it +uses the same color as the Deskbar.
  • +
+ +

Version 1.1 (Tuesday, 28 March 2000)

+ +
    +
  • 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.
  • +
+ +

Version 1.0 (Saturday, 14 August 1999)

+ +
    +
  • First version.
  • +
+ + +