From 6e645865304e06c60123df84c048753a2c35ee17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Wed, 29 Jul 2009 19:13:29 +0000 Subject: [PATCH] Clean-up git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31935 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../tracker/zipomatic/GenericThread.cpp | 4 +- src/add-ons/tracker/zipomatic/GenericThread.h | 2 +- src/add-ons/tracker/zipomatic/ZipOMatic.cpp | 180 ++++---- src/add-ons/tracker/zipomatic/ZipOMatic.h | 25 +- src/add-ons/tracker/zipomatic/ZipOMatic.rdef | 2 +- .../tracker/zipomatic/ZipOMaticActivity.cpp | 192 +++++---- .../tracker/zipomatic/ZipOMaticActivity.h | 50 ++- .../tracker/zipomatic/ZipOMaticMisc.cpp | 13 +- src/add-ons/tracker/zipomatic/ZipOMaticMisc.h | 19 +- .../tracker/zipomatic/ZipOMaticSettings.cpp | 32 +- .../tracker/zipomatic/ZipOMaticSettings.h | 47 +-- .../tracker/zipomatic/ZipOMaticView.cpp | 97 +++-- src/add-ons/tracker/zipomatic/ZipOMaticView.h | 28 +- .../tracker/zipomatic/ZipOMaticWindow.cpp | 384 ++++++++---------- .../tracker/zipomatic/ZipOMaticWindow.h | 60 +-- .../tracker/zipomatic/ZipperThread.cpp | 12 +- 16 files changed, 553 insertions(+), 594 deletions(-) diff --git a/src/add-ons/tracker/zipomatic/GenericThread.cpp b/src/add-ons/tracker/zipomatic/GenericThread.cpp index c7dfeeb0a4..224255f581 100644 --- a/src/add-ons/tracker/zipomatic/GenericThread.cpp +++ b/src/add-ons/tracker/zipomatic/GenericThread.cpp @@ -11,7 +11,7 @@ GenericThread::GenericThread(const char* thread_name, int32 priority, BMessage* message) : fThreadDataStore(message), - fThreadId(spawn_thread (_ThreadFunction, thread_name, priority, this)), + fThreadId(spawn_thread(_ThreadFunction, thread_name, priority, this)), fExecuteUnitSem(create_sem(1, "fExecuteUnitSem")), fQuitRequested(false), fThreadIsPaused(false) @@ -62,7 +62,7 @@ GenericThread::ThreadFunction() // Subclass and override if (status != B_OK) - ExecuteUnitFailed (status); + ExecuteUnitFailed(status); // Subclass and override EndUnit(); diff --git a/src/add-ons/tracker/zipomatic/GenericThread.h b/src/add-ons/tracker/zipomatic/GenericThread.h index 16742079b4..9134778e4f 100644 --- a/src/add-ons/tracker/zipomatic/GenericThread.h +++ b/src/add-ons/tracker/zipomatic/GenericThread.h @@ -28,7 +28,7 @@ public: status_t Kill(); void ExitWithReturnValue(status_t returnValue); - status_t SetExitCallback(void (* callback)(void*), + status_t SetExitCallback(void (*callback)(void*), void* data); status_t WaitForThread(status_t* exitValue); diff --git a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp index 90098cef4e..387b93a973 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp @@ -1,176 +1,159 @@ // license: public domain // authors: jonas.sundstrom@kirilla.com -#include -#include -#include #include "ZipOMatic.h" + +#include +#include + #include "ZipOMaticMisc.h" #include "ZipOMaticWindow.h" -extern "C" void -process_refs(entry_ref dir_ref, BMessage * msg, void *) -{ - msg->AddRef("dir_ref", & dir_ref); - status_t status = B_OK; - type_code ref_type = B_REF_TYPE; - int32 ref_count = 0; +extern "C" void +process_refs(entry_ref dirRef, BMessage* message, void*) +{ + status_t status = B_OK; + type_code refType = B_REF_TYPE; + int32 refCount = 0; - status = msg->GetInfo("refs", & ref_type, & ref_count); - if (status != B_OK || ref_count < 1) - be_roster->Launch (ZIPOMATIC_APP_SIG); + status = message->GetInfo("refs", &refType, &refCount); + if (status != B_OK || refCount < 1) + be_roster->Launch(ZIPOMATIC_APP_SIG); else - be_roster->Launch (ZIPOMATIC_APP_SIG, msg ); + be_roster->Launch(ZIPOMATIC_APP_SIG, message); } -int main() + +int +main() { ZipOMatic app; app.Run(); - return (0); + return 0; } -ZipOMatic::ZipOMatic (void) - : BApplication (ZIPOMATIC_APP_SIG), - m_got_refs (false) + +ZipOMatic::ZipOMatic() + : + BApplication(ZIPOMATIC_APP_SIG), + fGotRefs(false) { - PRINT(("ZipOMatic::ZipOMatic()\n")); - - // void + } -ZipOMatic::~ZipOMatic (void) + +ZipOMatic::~ZipOMatic() { - PRINT(("ZipOMatic::~ZipOMatic()\n")); - - fflush(stdout); + } + void -ZipOMatic::RefsReceived (BMessage * a_message) +ZipOMatic::RefsReceived(BMessage* message) { - PRINT(("ZipOMatic::RefsReceived()\n")); - if (IsLaunching()) - m_got_refs = true; + fGotRefs = true; - BMessage * msg = new BMessage (* a_message); + BMessage* msg = new BMessage(*message); - UseExistingOrCreateNewWindow(msg); + _UseExistingOrCreateNewWindow(msg); } + void -ZipOMatic::ReadyToRun (void) +ZipOMatic::ReadyToRun() { - PRINT(("ZipOMatic::ReadyToRun()\n")); - - if (m_got_refs) - { - // nothing - wait on window(s) to finish - } - else - UseExistingOrCreateNewWindow(); + if (!fGotRefs) + _UseExistingOrCreateNewWindow(); } + void -ZipOMatic::MessageReceived (BMessage * a_message) +ZipOMatic::MessageReceived(BMessage* message) { - PRINT(("ZipOMatic::MessageReceived()\n")); - - switch(a_message->what) - { + switch (message->what) { case ZIPPO_WINDOW_QUIT: - - snooze (200000); - if (CountWindows() == 0) - Quit(); - break; + snooze(200000); + if (CountWindows() == 0) + Quit(); + break; case B_SILENT_RELAUNCH: - - SilentRelaunch(); - break; - - default: BApplication::MessageReceived(a_message); break; + _SilentRelaunch(); + break; + + default: + BApplication::MessageReceived(message); + break; } - } + bool ZipOMatic::QuitRequested (void) { - // intelligent (?) closing of the windows - // - // overriding BApplication::QuitRequested(); + // Overriding BApplication's default behaviour on purpose + // so we can have multiple zippers pause in unison. if (CountWindows() <= 0) return true; - BList window_list (5); - int32 window_count = 0; - BWindow * window; + BList list(5); + BWindow* window; - // build list of windows - while (1) - { - window = WindowAt(window_count++); + for (int32 i = 0;; i++) { + window = WindowAt(i); if (window == NULL) break; - window_list.AddItem(window); + list.AddItem(window); } - // ask windows to quit - while (1) - { - window = (BWindow *) window_list.RemoveItem(int32(0)); + while (true) { + window = (BWindow*) list.RemoveItem(int32(0)); if (window == NULL) break; - if (window->Lock()) - { + if (window->Lock()) { window->PostMessage(B_QUIT_REQUESTED); window->Unlock(); } } - PRINT(("CountWindows(): %ld\n", CountWindows())); - if (CountWindows() <= 0) return true; - return false; // default: stay alive + return false; } + void -ZipOMatic::SilentRelaunch (void) +ZipOMatic::_SilentRelaunch() { - UseExistingOrCreateNewWindow(); + _UseExistingOrCreateNewWindow(); } -void -ZipOMatic::UseExistingOrCreateNewWindow (BMessage * a_message) -{ - int32 window_count = 0; - ZippoWindow * window; - bool found_non_busy_window = false; - while (1) - { - window = dynamic_cast(WindowAt(window_count++)); +void +ZipOMatic::_UseExistingOrCreateNewWindow(BMessage* message) +{ + int32 windowCount = 0; + ZippoWindow* window; + bool foundNonBusyWindow = false; + + while (1) { + window = dynamic_cast(WindowAt(windowCount++)); if (window == NULL) break; - if (window->Lock()) - { - if (! window->IsZipping()) - { - found_non_busy_window = true; - if (a_message != NULL) - window->PostMessage(a_message); + if (window->Lock()) { + if (!window->IsZipping()) { + foundNonBusyWindow = true; + if (message != NULL) + window->PostMessage(message); window->Activate(); window->Unlock(); break; @@ -179,9 +162,10 @@ ZipOMatic::UseExistingOrCreateNewWindow (BMessage * a_message) } } - if (! found_non_busy_window) + if (!foundNonBusyWindow) { - ZippoWindow * m_window = new ZippoWindow(a_message); - m_window->Show(); + ZippoWindow * window = new ZippoWindow(message); + window->Show(); } } + diff --git a/src/add-ons/tracker/zipomatic/ZipOMatic.h b/src/add-ons/tracker/zipomatic/ZipOMatic.h index 57f4845ebb..c516f9c665 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMatic.h +++ b/src/add-ons/tracker/zipomatic/ZipOMatic.h @@ -1,28 +1,29 @@ #ifndef _ZIPOMATIC_H_ #define _ZIPOMATIC_H_ + #include #include + class ZipOMatic : public BApplication { public: - ZipOMatic (void); - ~ZipOMatic (void); + ZipOMatic(); + ~ZipOMatic(); - virtual void ReadyToRun (void); - virtual void RefsReceived (BMessage * a_message); - virtual void MessageReceived (BMessage * a_message); - virtual bool QuitRequested (void); + virtual void ReadyToRun(); + virtual void RefsReceived(BMessage* message); + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); - void SilentRelaunch (void); - void UseExistingOrCreateNewWindow (BMessage * a_message = NULL); - private: + void _SilentRelaunch(); + void _UseExistingOrCreateNewWindow(BMessage* + message = NULL); - bool m_got_refs; - - + bool fGotRefs; }; #endif // _ZIPOMATIC_H_ + diff --git a/src/add-ons/tracker/zipomatic/ZipOMatic.rdef b/src/add-ons/tracker/zipomatic/ZipOMatic.rdef index 0380e9c4ac..854e5c78e3 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMatic.rdef +++ b/src/add-ons/tracker/zipomatic/ZipOMatic.rdef @@ -14,7 +14,7 @@ resource app_version { internal = 1, short_info = "ZipOMatic", - long_info = "ZipOMatic, Copyright 2003-2008 Haiku Inc." + long_info = "ZipOMatic, Copyright 2003-2009 Haiku Inc." }; resource file_types message { diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticActivity.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticActivity.cpp index d32ea26918..5f8ec2b5ee 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticActivity.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticActivity.cpp @@ -1,96 +1,105 @@ // license: public domain // authors: jonas.sundstrom@kirilla.com + #include "ZipOMaticActivity.h" -Activity::Activity (BRect a_rect, const char * a_name, uint32 a_resizing_mode, uint32 a_flags) -: BView (a_rect, a_name, a_resizing_mode, a_flags), - m_is_running (false), - m_barberpole_bitmap (NULL) + +Activity::Activity(BRect frame, const char* name, uint32 resizingMode, + uint32 flags) + : + BView(frame, name, resizingMode, flags), + fIsRunning(false), + fBitmap(NULL) { SetViewColor(B_TRANSPARENT_COLOR); - m_pattern.data[0] = 0x0f; - m_pattern.data[1] = 0x1e; - m_pattern.data[2] = 0x3c; - m_pattern.data[3] = 0x78; - m_pattern.data[4] = 0xf0; - m_pattern.data[5] = 0xe1; - m_pattern.data[6] = 0xc3; - m_pattern.data[7] = 0x87; + fPattern.data[0] = 0x0f; + fPattern.data[1] = 0x1e; + fPattern.data[2] = 0x3c; + fPattern.data[3] = 0x78; + fPattern.data[4] = 0xf0; + fPattern.data[5] = 0xe1; + fPattern.data[6] = 0xc3; + fPattern.data[7] = 0x87; - CreateBitmap(); + _CreateBitmap(); }; + Activity::~Activity() { - // subviews are deleted by superclass - - delete m_barberpole_bitmap; + delete fBitmap; } + void Activity::Start() { - m_is_running = true; + fIsRunning = true; Window()->SetPulseRate(100000); SetFlags(Flags() | B_PULSE_NEEDED); Invalidate(); } + void Activity::Pause() { Window()->SetPulseRate(500000); - SetFlags(Flags() & (~ B_PULSE_NEEDED)); + SetFlags(Flags() & (~B_PULSE_NEEDED)); Invalidate(); } + void Activity::Stop() { - m_is_running = false; + fIsRunning = false; Window()->SetPulseRate(500000); - SetFlags(Flags() & (~ B_PULSE_NEEDED)); + SetFlags(Flags() & (~B_PULSE_NEEDED)); Invalidate(); } + bool Activity::IsRunning() { - return m_is_running; + return fIsRunning; } + void Activity::Pulse() { - uchar tmp = m_pattern.data[7]; - + uchar tmp = fPattern.data[7]; + for (int j = 7; j > 0; --j) - { - m_pattern.data[j] = m_pattern.data[j-1]; - } + fPattern.data[j] = fPattern.data[j-1]; - m_pattern.data[0] = tmp; + fPattern.data[0] = tmp; Invalidate(); } + void -Activity::Draw(BRect a_rect) +Activity::Draw(BRect rect) { - DrawIntoBitmap(IsRunning()); + _DrawOnBitmap(IsRunning()); SetDrawingMode(B_OP_COPY); - DrawBitmap(m_barberpole_bitmap); + DrawBitmap(fBitmap); } -void Activity::DrawIntoBitmap (bool running) -{ - if (m_barberpole_bitmap->Lock()) - { - BRect a_rect = m_barberpole_bitmap->Bounds(); - m_barberpole_bitmap_view->SetDrawingMode(B_OP_COPY); +void +Activity::_DrawOnBitmap(bool running) +{ + if (fBitmap->Lock()) + { + BRect rect = fBitmap->Bounds(); + + fBitmapView->SetDrawingMode(B_OP_COPY); rgb_color color; color.red = 0; @@ -101,11 +110,11 @@ void Activity::DrawIntoBitmap (bool running) if (running) color.blue = 200; - m_barberpole_bitmap_view->SetHighColor(color); + fBitmapView->SetHighColor(color); // draw the pole - a_rect.InsetBy(2,2); - m_barberpole_bitmap_view->FillRect(a_rect, m_pattern); + rect.InsetBy(2,2); + fBitmapView->FillRect(rect, fPattern); // draw frame @@ -113,98 +122,105 @@ void Activity::DrawIntoBitmap (bool running) color.red = 150; color.green = 150; color.blue = 150; - m_barberpole_bitmap_view->SetHighColor(color); - m_barberpole_bitmap_view->SetDrawingMode(B_OP_OVER); - BPoint point_a = m_barberpole_bitmap->Bounds().LeftTop(); - BPoint point_b = m_barberpole_bitmap->Bounds().LeftBottom(); + fBitmapView->SetHighColor(color); + fBitmapView->SetDrawingMode(B_OP_OVER); + BPoint point_a = fBitmap->Bounds().LeftTop(); + BPoint point_b = fBitmap->Bounds().LeftBottom(); point_b.y -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); point_a.x += 1; point_b.x += 1; point_b.y -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); // top - point_a = m_barberpole_bitmap->Bounds().LeftTop(); - point_b = m_barberpole_bitmap->Bounds().RightTop(); + point_a = fBitmap->Bounds().LeftTop(); + point_b = fBitmap->Bounds().RightTop(); point_b.x -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); point_a.y += 1; point_b.y += 1; point_b.x -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); // right color.red = 255; color.green = 255; color.blue = 255; - m_barberpole_bitmap_view->SetHighColor(color); - point_a = m_barberpole_bitmap->Bounds().RightTop(); - point_b = m_barberpole_bitmap->Bounds().RightBottom(); - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->SetHighColor(color); + point_a = fBitmap->Bounds().RightTop(); + point_b = fBitmap->Bounds().RightBottom(); + fBitmapView->StrokeLine(point_a, point_b); point_a.y += 1; point_a.x -= 1; point_b.x -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); // bottom - point_a = m_barberpole_bitmap->Bounds().LeftBottom(); - point_b = m_barberpole_bitmap->Bounds().RightBottom(); - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + point_a = fBitmap->Bounds().LeftBottom(); + point_b = fBitmap->Bounds().RightBottom(); + fBitmapView->StrokeLine(point_a, point_b); point_a.x += 1; point_a.y -= 1; point_b.y -= 1; - m_barberpole_bitmap_view->StrokeLine(point_a, point_b); + fBitmapView->StrokeLine(point_a, point_b); // some blending color.red = 150; color.green = 150; color.blue = 150; - m_barberpole_bitmap_view->SetHighColor(color); - m_barberpole_bitmap_view->SetDrawingMode(B_OP_SUBTRACT); - m_barberpole_bitmap_view->StrokeRect(a_rect); + fBitmapView->SetHighColor(color); + fBitmapView->SetDrawingMode(B_OP_SUBTRACT); + fBitmapView->StrokeRect(rect); - a_rect.InsetBy(1,1); - LightenBitmapHighColor(& color); - m_barberpole_bitmap_view->StrokeRect(a_rect); + rect.InsetBy(1,1); + _LightenBitmapHighColor(& color); + fBitmapView->StrokeRect(rect); - a_rect.InsetBy(1,1); - LightenBitmapHighColor(& color); - m_barberpole_bitmap_view->StrokeRect(a_rect); + rect.InsetBy(1,1); + _LightenBitmapHighColor(& color); + fBitmapView->StrokeRect(rect); - a_rect.InsetBy(1,1); - LightenBitmapHighColor(& color); - m_barberpole_bitmap_view->StrokeRect(a_rect); + rect.InsetBy(1,1); + _LightenBitmapHighColor(& color); + fBitmapView->StrokeRect(rect); - a_rect.InsetBy(1,1); - LightenBitmapHighColor(& color); - m_barberpole_bitmap_view->StrokeRect(a_rect); + rect.InsetBy(1,1); + _LightenBitmapHighColor(& color); + fBitmapView->StrokeRect(rect); - m_barberpole_bitmap_view->Sync(); - m_barberpole_bitmap->Unlock(); + fBitmapView->Sync(); + fBitmap->Unlock(); } } -void Activity::LightenBitmapHighColor (rgb_color * a_color) + +void +Activity::_LightenBitmapHighColor(rgb_color* color) { - a_color->red -= 30; - a_color->green -= 30; - a_color->blue -= 30; + color->red -= 30; + color->green -= 30; + color->blue -= 30; - m_barberpole_bitmap_view->SetHighColor(* a_color); + fBitmapView->SetHighColor(*color); } -void Activity::CreateBitmap (void) + +void +Activity::_CreateBitmap(void) { - BRect barberpole_rect = Bounds(); - m_barberpole_bitmap = new BBitmap(barberpole_rect, B_CMAP8, true); - m_barberpole_bitmap_view = new BView(Bounds(), "buffer", B_FOLLOW_NONE, 0); - m_barberpole_bitmap->AddChild(m_barberpole_bitmap_view); + BRect rect = Bounds(); + fBitmap = new BBitmap(rect, B_CMAP8, true); + fBitmapView = new BView(Bounds(), "buffer", B_FOLLOW_NONE, 0); + fBitmap->AddChild(fBitmapView); } -void Activity::FrameResized (float a_width, float a_height) + +void +Activity::FrameResized(float width, float height) { - delete m_barberpole_bitmap; - CreateBitmap(); + delete fBitmap; + _CreateBitmap(); Invalidate(); } + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticActivity.h b/src/add-ons/tracker/zipomatic/ZipOMaticActivity.h index c345f1bd80..7fd4ac9bf4 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticActivity.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticActivity.h @@ -3,39 +3,37 @@ #include -#include -#include #include #include +#include +#include + class Activity : public BView { - public: - Activity (BRect a_rect, const char * a_name, uint32 a_resizing_mode, - uint32 a_flags); - ~Activity (); +public: + Activity(BRect frame, const char* name, + uint32 resizing_mode, uint32 flags); + ~Activity(); - void Start (); - void Pause (); - void Stop (); - bool IsRunning (); - virtual void Pulse (); - virtual void Draw (BRect a_draw); - virtual void FrameResized (float a_width, float a_height); + void Start(); + void Pause(); + void Stop(); + bool IsRunning(); + virtual void Pulse(); + virtual void Draw(BRect draw); + virtual void FrameResized(float width, float height); - protected: - void CreateBitmap (void); - void LightenBitmapHighColor (rgb_color * a_color); - void DrawIntoBitmap (bool running); - - bool m_is_running; - pattern m_pattern; - - BBitmap * m_barberpole_bitmap; - BView * m_barberpole_bitmap_view; - - private: +private: + void _CreateBitmap(); + void _LightenBitmapHighColor(rgb_color* color); + void _DrawOnBitmap(bool running); + bool fIsRunning; + pattern fPattern; + BBitmap* fBitmap; + BView* fBitmapView; }; -#endif +#endif // _ACTIVITY_H_ + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticMisc.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticMisc.cpp index 7b7a6a2d14..197fa14af3 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticMisc.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticMisc.cpp @@ -1,22 +1,21 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2009, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Jonas Sundström, jonas.sundstrom@kirilla.com + * Jonas Sundström, jonas@kirilla.com */ #include "ZipOMaticMisc.h" -#include -#include - #include +#include + status_t -find_and_create_directory(directory_which which, BVolume* volume, +FindAndCreateDirectory(directory_which which, BVolume* volume, const char* relativePath, BPath* fullPath) { BPath path; @@ -46,7 +45,7 @@ find_and_create_directory(directory_which which, BVolume* volume, void -error_message(const char* text, int32 status) +ErrorMessage(const char* text, int32 status) { PRINT(("%s: %s\n", text, strerror(status))); } diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticMisc.h b/src/add-ons/tracker/zipomatic/ZipOMaticMisc.h index 08d042a4d8..a3603266d8 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticMisc.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticMisc.h @@ -1,9 +1,9 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2009, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Jonas Sundström, jonas.sundstrom@kirilla.com + * Jonas Sundström, jonas@kirilla.com */ #ifndef ZIPOMATIC_MISC_H #define ZIPOMATIC_MISC_H @@ -11,18 +11,19 @@ #include #include - -class BPath; -class BVolume; +#include +#include #define ZIPOMATIC_APP_SIG "application/x-vnd.haiku.zip-o-matic" -#define ZIPOMATIC_APP_NAME "ZipOMatic" #define ZIPPO_WINDOW_QUIT 'winq' -status_t find_and_create_directory(directory_which which, BVolume* volume = NULL, - const char* relativePath = NULL, BPath* fullPath = NULL); -void error_message(const char* text, int32 status); +status_t FindAndCreateDirectory(directory_which which, + BVolume* volume = NULL, const char* relativePath = NULL, + BPath* fullPath = NULL); + +void ErrorMessage(const char* text, int32 status); #endif // ZIPOMATIC_MISC_H + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticSettings.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticSettings.cpp index 62595f765c..37b1ef56ce 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticSettings.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticSettings.cpp @@ -1,42 +1,45 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2009, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Jonas Sundström, jonas.sundstrom@kirilla.com + * Jonas Sundström, jonas@kirilla.com */ // TODO: proper locking <<--------- -#include "ZipOMaticMisc.h" + #include "ZipOMaticSettings.h" #include -#include -#include #include -#include #include +#include +#include + +#include "ZipOMaticMisc.h" ZippoSettings::ZippoSettings() : fBaseDir(B_USER_SETTINGS_DIRECTORY) { - PRINT(("ZippoSettings()\n")); + } ZippoSettings::ZippoSettings(BMessage& message) - : BMessage(message), + : + BMessage(message), fBaseDir(B_USER_SETTINGS_DIRECTORY) { - PRINT(("ZippoSettings(a_message)\n")); + } ZippoSettings::~ZippoSettings() { + } @@ -46,17 +49,16 @@ ZippoSettings::SetTo(const char* filename, BVolume* volume, { status_t status = B_OK; - // copy to members fBaseDir = baseDir; fRelativePath = relativePath; fFilename = filename; - // sanity check if (volume == NULL) { BVolumeRoster volumeRoster; volumeRoster.GetBootVolume(&fVolume); - } else + } else { fVolume = *volume; + } status = fVolume.InitCheck(); if (status != B_OK) @@ -77,8 +79,6 @@ ZippoSettings::InitCheck() status_t ZippoSettings::ReadSettings() { - PRINT(("ZippoSettings::ReadSettings()\n")); - BFile file; status_t status = _GetSettingsFile(&file, B_READ_ONLY); if (status != B_OK) @@ -91,8 +91,6 @@ ZippoSettings::ReadSettings() status_t ZippoSettings::WriteSettings() { - PRINT(("ZippoSettings::WriteSettings()\n")); - BFile file; status_t status = _GetSettingsFile(&file, B_WRITE_ONLY | B_ERASE_FILE); if (status != B_OK) @@ -106,7 +104,7 @@ status_t ZippoSettings::_GetSettingsFile(BFile* file, uint32 openMode) { BPath path; - status_t status = find_and_create_directory(fBaseDir, &fVolume, + status_t status = FindAndCreateDirectory(fBaseDir, &fVolume, fRelativePath.String(), &path); if (status != B_OK) return status; diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticSettings.h b/src/add-ons/tracker/zipomatic/ZipOMaticSettings.h index 16c99f9878..c3825dcaa7 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticSettings.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticSettings.h @@ -1,12 +1,12 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2009, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Jonas Sundström, jonas.sundstrom@kirilla.com + * Jonas Sundström, jonas@kirilla.com */ -#ifndef ZIPOMATIC_SETTINGS_H -#define ZIPOMATIC_SETTINGS_H +#ifndef _ZIPOMATIC_SETTINGS_H +#define _ZIPOMATIC_SETTINGS_H #include @@ -16,27 +16,28 @@ class ZippoSettings : public BMessage { - public: - ZippoSettings(); - ZippoSettings(BMessage& message); - ~ZippoSettings(); +public: + ZippoSettings(); + ZippoSettings(BMessage& message); + ~ZippoSettings(); - status_t SetTo(const char* filename, BVolume* volume = NULL, - directory_which baseDir = B_USER_SETTINGS_DIRECTORY, - const char* relativePath = NULL); + status_t SetTo(const char* filename, BVolume* volume = NULL, + directory_which baseDir = + B_USER_SETTINGS_DIRECTORY, + const char* relativePath = NULL); + status_t InitCheck(); + + status_t ReadSettings(); + status_t WriteSettings(); - status_t InitCheck(); +private: + status_t _GetSettingsFile(BFile* file, uint32 openMode); - status_t ReadSettings(); - status_t WriteSettings(); - - private: - status_t _GetSettingsFile(BFile* file, uint32 openMode); - - BVolume fVolume; - directory_which fBaseDir; - BString fRelativePath; - BString fFilename; + BVolume fVolume; + directory_which fBaseDir; + BString fRelativePath; + BString fFilename; }; -#endif // ZIPOMATIC_SETTINGS_H +#endif // _ZIPOMATIC_SETTINGS_H + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp index bdea48fa80..edc045576b 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp @@ -1,87 +1,82 @@ // license: public domain -// authors: jonas.sundstrom@kirilla.com +// authors: Jonas Sundström, jonas@kirilla.com + -#include "ZipOMaticActivity.h" #include "ZipOMaticView.h" -ZippoView::ZippoView (BRect a_rect) -: BBox (a_rect, "zipomatic_view", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER), - m_stop_button (NULL) + +ZippoView::ZippoView(BRect rect) + : + BBox(rect, "zipomatic_view", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER), + fStopButton(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - // "Stop" button - BRect button_rect (a_rect.right-82, a_rect.bottom-32, a_rect.right-12, a_rect.bottom-12); - m_stop_button = new BButton(button_rect,"stop_button","Stop", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT); - m_stop_button->SetEnabled(false); - AddChild(m_stop_button); + fStopButton = new BButton( + BRect(rect.right-82, rect.bottom-32, rect.right-12, rect.bottom-12), + "stop_button", "Stop", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT); + fStopButton->SetEnabled(false); + AddChild(fStopButton); - // activity view - BRect activity_rect (a_rect.left+14, a_rect.top+15, a_rect.right-15, a_rect.top+31); - m_activity_view = new Activity (activity_rect, "activity_view", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS); - AddChild(m_activity_view); + BRect activity_rect(rect.left+14, rect.top+15, rect.right-15, rect.top+31); + fActivityView = new Activity(activity_rect, "activity_view", + B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS); + AddChild(fActivityView); - // text views - BRect archive_rect (a_rect.left+14, a_rect.top+30, a_rect.right-15, a_rect.top+47); - m_archive_name_view = new BStringView (archive_rect, "archive_text", " ", B_FOLLOW_LEFT_RIGHT); - AddChild (m_archive_name_view); - - BRect ouput_rect (a_rect.left+14, a_rect.top+47, a_rect.right-15, a_rect.top+66); - m_zip_output_view = new BStringView (ouput_rect, "output_text", "Drop files to zip.", B_FOLLOW_LEFT_RIGHT); - AddChild (m_zip_output_view); + BRect archive_rect(rect.left+14, rect.top+30, rect.right-15, rect.top+47); + fArchiveNameView = new BStringView(archive_rect, "archive_text", " ", + B_FOLLOW_LEFT_RIGHT); + AddChild(fArchiveNameView); + BRect ouput_rect(rect.left+14, rect.top+47, rect.right-15, rect.top+66); + fZipOutputView = new BStringView(ouput_rect, "output_text", + "Drop files to zip.", B_FOLLOW_LEFT_RIGHT); + AddChild(fZipOutputView); } -void ZippoView::Draw (BRect a_update_rect) -{ - BBox::Draw(a_update_rect); - // fBox->DrawBitmap(fIconBitmap,BPoint(178,26)); - const rgb_color grey_accent = {128,128,128,255}; - const rgb_color darker_grey = {108,108,108,255}; - const rgb_color plain_white = {255,255,255,255}; - const rgb_color deep_black = {255,255,255,255}; +void ZippoView::Draw(BRect rect) +{ + BBox::Draw(rect); + + const rgb_color grey_accent = {128,128,128,255}; + const rgb_color darker_grey = {108,108,108,255}; + const rgb_color plain_white = {255,255,255,255}; + const rgb_color black = {0, 0, 0, 255}; // "preflet" bottom, right grey accent lines - SetHighColor(grey_accent); - StrokeLine (BPoint(Bounds().right, Bounds().top), + StrokeLine(BPoint(Bounds().right, Bounds().top), BPoint(Bounds().right, Bounds().bottom)); - StrokeLine (BPoint(Bounds().left, Bounds().bottom), + StrokeLine(BPoint(Bounds().left, Bounds().bottom), BPoint(Bounds().right, Bounds().bottom)); // divider SetHighColor(darker_grey); - StrokeLine (BPoint(Bounds().left+15, Bounds().top+71), + StrokeLine(BPoint(Bounds().left+15, Bounds().top+71), BPoint(Bounds().right-16, Bounds().top+71)); SetHighColor(plain_white); - StrokeLine (BPoint(Bounds().left+15, Bounds().top+72), + StrokeLine(BPoint(Bounds().left+15, Bounds().top+72), BPoint(Bounds().right-16, Bounds().top+72)); - // text - SetHighColor(deep_black); - - + SetHighColor(black); } -void ZippoView::AllAttached (void) -{ - -} -void ZippoView::FrameMoved (BPoint a_point) -{ - Invalidate(); -} - -void ZippoView::FrameResized (float a_width, float a_height) +void +ZippoView::FrameMoved(BPoint point) { Invalidate(); } +void +ZippoView::FrameResized(float width, float height) +{ + Invalidate(); +} + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticView.h b/src/add-ons/tracker/zipomatic/ZipOMaticView.h index 9e26c8e8cc..ac394a9e10 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticView.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticView.h @@ -5,27 +5,23 @@ #include #include -class Activity; +#include "ZipOMaticActivity.h" + class ZippoView : public BBox { - public: - ZippoView (BRect frame); +public: + ZippoView(BRect frame); - virtual void Draw (BRect frame); - virtual void AllAttached (void); - virtual void FrameMoved (BPoint a_point); - virtual void FrameResized (float a_width, float a_height); + virtual void Draw(BRect frame); + virtual void FrameMoved(BPoint point); + virtual void FrameResized(float width, float height); - BButton * m_stop_button; - Activity * m_activity_view; - - BStringView * m_archive_name_view; - BStringView * m_zip_output_view; - - private: - - + BButton* fStopButton; + Activity* fActivityView; + BStringView* fArchiveNameView; + BStringView* fZipOutputView; }; #endif // __ZIPPO_VIEW_H__ + diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp index e129e8bb4d..ccddab6d97 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp @@ -1,336 +1,304 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2009, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Jonas Sundström, jonas.sundstrom@kirilla.com + * Jonas Sundström, jonas@kirilla.com */ -#include +#include "ZipOMaticWindow.h" #include #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include #include "ZipOMatic.h" #include "ZipOMaticActivity.h" #include "ZipOMaticMisc.h" #include "ZipOMaticView.h" -#include "ZipOMaticWindow.h" #include "ZipperThread.h" -ZippoWindow::ZippoWindow(BMessage * a_message) -: BWindow(BRect(200,200,430,310), "Zip-O-Matic", B_TITLED_WINDOW, B_NOT_V_RESIZABLE), // | B_NOT_ZOOMABLE), - m_zippo_settings (), - m_zipper_thread (NULL), - m_got_refs_at_window_startup (false), - m_zipping_was_stopped (false), - m_alert_invoker_message (new BMessage ('alrt')), - m_alert_window_invoker (new BInvoker (m_alert_invoker_message, NULL, this)) +ZippoWindow::ZippoWindow(BMessage* message) + : + BWindow(BRect(200, 200, 430, 310), "Zip-O-Matic", B_TITLED_WINDOW, + B_NOT_V_RESIZABLE), + fView(NULL), + fSettings(), + fThread(NULL), + fWindowGotRefs(false), + fZippingWasStopped(false), + fWindowInvoker(new BInvoker(new BMessage('alrt'), NULL, this)) { - PRINT(("ZippoWindow()\n")); + status_t status = B_OK; -// Settings - status_t status = B_OK; - - status = m_zippo_settings.SetTo("ZipOMatic.msg"); + status = fSettings.SetTo("ZipOMatic.msg"); if (status != B_OK) - error_message("ZippoWindow() - m_zippo_settings.SetTo()", status); + ErrorMessage("fSettings.SetTo()", status); - status = m_zippo_settings.InitCheck(); + status = fSettings.InitCheck(); if (status != B_OK) - error_message("ZippoWindow() - m_zippo_settings.InitCheck()", status); + ErrorMessage("fSettings.InitCheck()", status); -// Interface - zippoview = new ZippoView(Bounds()); - - AddChild (zippoview); + fView = new ZippoView(Bounds()); + AddChild(fView); - SetSizeLimits(Bounds().Width(), 15000, Bounds().Height(), Bounds().Height()); + SetSizeLimits(Bounds().Width(), 15000, Bounds().Height(), + Bounds().Height()); -// Settings, (on-screen location of window) - ReadSettings(); + _ReadSettings(); -// Start zipper thread - if (a_message != NULL) + if (message != NULL) { - m_got_refs_at_window_startup = true; - StartZipping (a_message); + fWindowGotRefs = true; + _StartZipping(message); } } + ZippoWindow::~ZippoWindow() { - PRINT(("ZippoWindow::~ZippoWindow()\n")); - - //delete m_alert_invoker_message; - delete m_alert_window_invoker; - - // anything left to clean up? + delete fWindowInvoker; } + void -ZippoWindow::MessageReceived (BMessage * a_message) +ZippoWindow::MessageReceived(BMessage* message) { - switch(a_message->what) - { - + switch (message->what) { case B_REFS_RECEIVED: - StartZipping (a_message); - break; + _StartZipping(message); + break; case B_SIMPLE_DATA: - if (IsZipping()) - { - a_message->what = B_REFS_RECEIVED; - be_app_messenger.SendMessage(a_message); - } - else - StartZipping (a_message); - break; + if (IsZipping()) { + message->what = B_REFS_RECEIVED; + be_app_messenger.SendMessage(message); + } else { + _StartZipping(message); + } + break; - case 'exit': // thread has finished (finished, quit, killed, we don't know) - // reset window state - { - m_zipper_thread = NULL; - zippoview->m_activity_view->Stop(); - zippoview->m_stop_button->SetEnabled(false); - zippoview->m_archive_name_view->SetText(" "); - if (m_zipping_was_stopped) - zippoview->m_zip_output_view->SetText("Stopped"); - else - zippoview->m_zip_output_view->SetText("Archive created OK"); - - CloseWindowOrKeepOpen(); - break; - } + case 'exit': + // thread has finished - (finished, quit, killed, we don't know) + fThread = NULL; + fView->fActivityView->Stop(); + fView->fStopButton->SetEnabled(false); + fView->fArchiveNameView->SetText(" "); + if (fZippingWasStopped) + fView->fZipOutputView->SetText("Stopped"); + else + fView->fZipOutputView->SetText("Archive created OK"); + + _CloseWindowOrKeepOpen(); + break; - case 'exrr': // thread has finished - // reset window state - - m_zipper_thread = NULL; - zippoview->m_activity_view->Stop(); - zippoview->m_stop_button->SetEnabled(false); - zippoview->m_archive_name_view->SetText(""); - zippoview->m_zip_output_view->SetText("Error creating archive"); - //CloseWindowOrKeepOpen(); - break; + case 'exrr': // thread has finished - badly + fThread = NULL; + fView->fActivityView->Stop(); + fView->fStopButton->SetEnabled(false); + fView->fArchiveNameView->SetText(""); + fView->fZipOutputView->SetText("Error creating archive"); + break; case 'strt': - { - BString archive_filename; - if (a_message->FindString("archive_filename", & archive_filename) == B_OK) - zippoview->m_archive_name_view->SetText(archive_filename.String()); - break; - } + { + BString string; + if (message->FindString("archive_filename", &string) == B_OK) + fView->fArchiveNameView->SetText(string.String()); + break; + } case 'outp': - { - BString zip_output; - if (a_message->FindString("zip_output", & zip_output) == B_OK) - zippoview->m_zip_output_view->SetText(zip_output.String()); - break; - } - + { + BString string; + if (message->FindString("zip_output", &string) == B_OK) + fView->fZipOutputView->SetText(string.String()); + break; + } + case 'alrt': - { - int32 which_button = -1; - if (a_message->FindInt32("which", & which_button) == B_OK) - if (which_button == 0) - StopZipping(); - else - { - if (m_zipper_thread != NULL) - m_zipper_thread->ResumeExternalZip(); - - zippoview->m_activity_view->Start(); - } - break; - } - - default: BWindow::MessageReceived(a_message); break; + { + int32 which_button = -1; + if (message->FindInt32("which", &which_button) == B_OK) { + if (which_button == 0) { + _StopZipping(); + } else { + if (fThread != NULL) + fThread->ResumeExternalZip(); + + fView->fActivityView->Start(); + } + } + break; + } + + default: + BWindow::MessageReceived(message); + break; } } + bool -ZippoWindow::QuitRequested (void) +ZippoWindow::QuitRequested() { - PRINT(("ZippoWindow::QuitRequested()\n")); - - if (m_zipper_thread == NULL) - { - WriteSettings(); + if (fThread == NULL) { + _WriteSettings(); be_app_messenger.SendMessage(ZIPPO_WINDOW_QUIT); return true; - } - else - { - if (m_zipper_thread != NULL) - m_zipper_thread->SuspendExternalZip(); + } else { + if (fThread != NULL) + fThread->SuspendExternalZip(); - zippoview->m_activity_view->Pause(); + fView->fActivityView->Pause(); - BAlert * quit_requester = new BAlert ("Stop or Continue", "Are you sure you want to " - "stop creating this archive?", "Stop", "Continue", - NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT); - quit_requester->Go(m_alert_window_invoker); + BAlert* alert = new BAlert("Stop or Continue", + "Are you sure you want to stop creating this archive?", "Stop", + "Continue", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->Go(fWindowInvoker); return false; } } + status_t -ZippoWindow::ReadSettings (void) +ZippoWindow::_ReadSettings() { - status_t status = B_OK; + status_t status = B_OK; - status = m_zippo_settings.InitCheck(); + status = fSettings.InitCheck(); if (status != B_OK) - error_message("m_zippo_settings.InitCheck()", status); + ErrorMessage("fSettings.InitCheck()", status); - status = m_zippo_settings.ReadSettings(); + status = fSettings.ReadSettings(); if (status != B_OK) - error_message("m_zippo_settings.ReadSettings()", status); + ErrorMessage("fSettings.ReadSettings()", status); - BRect window_rect; + BRect windowRect; - status = m_zippo_settings.FindRect("window_rect", & window_rect); + status = fSettings.FindRect("windowRect", &windowRect); if (status != B_OK) { - error_message("m_settings_message->FindRect(window_rect)", status); + ErrorMessage("fSettings.FindRect(windowRect)", status); return status; } - ResizeTo (window_rect.Width(), window_rect.Height()); - MoveTo (window_rect.LeftTop()); + ResizeTo(windowRect.Width(), windowRect.Height()); + MoveTo(windowRect.LeftTop()); return B_OK; } + status_t -ZippoWindow::WriteSettings (void) +ZippoWindow::_WriteSettings() { - status_t status = B_OK; + status_t status = B_OK; - status = m_zippo_settings.InitCheck(); + status = fSettings.InitCheck(); if (status != B_OK) - error_message("m_zippo_settings.InitCheck()", status); + ErrorMessage("fSettings.InitCheck()", status); - status = m_zippo_settings.MakeEmpty(); + status = fSettings.MakeEmpty(); if (status != B_OK) - error_message("m_zippo_settings.MakeEmpty()", status); + ErrorMessage("fSettings.MakeEmpty()", status); - status = m_zippo_settings.AddRect("window_rect", Frame()); + status = fSettings.AddRect("windowRect", Frame()); if (status != B_OK) { - error_message("m_settings_message->AddRect(window_rect)", status); + ErrorMessage("fSettings.AddRect(windowRect)", status); return status; } - status = m_zippo_settings.WriteSettings(); + status = fSettings.WriteSettings(); if (status != B_OK) { - error_message("m_zippo_settings.WriteSettings()", status); + ErrorMessage("fSettings.WriteSettings()", status); return status; } - return B_OK; } -void -ZippoWindow::StartZipping (BMessage * a_message) -{ - PRINT(("ZippoWindow::StartZipping()\n")); - - zippoview->m_stop_button->SetEnabled(true); - zippoview->m_activity_view->Start(); - - m_zipper_thread = new ZipperThread (a_message, this); - m_zipper_thread->Start(); - - m_zipping_was_stopped = false; -} void -ZippoWindow::StopZipping (void) +ZippoWindow::_StartZipping(BMessage* message) { - PRINT(("ZippoWindow::StopZipping()\n")); + fView->fStopButton->SetEnabled(true); + fView->fActivityView->Start(); - m_zipping_was_stopped = true; - - zippoview->m_stop_button->SetEnabled(false); + fThread = new ZipperThread(message, this); + fThread->Start(); - zippoview->m_activity_view->Stop(); - - m_zipper_thread->InterruptExternalZip(); - m_zipper_thread->Quit(); - - status_t status = B_OK; - m_zipper_thread->WaitForThread (& status); - m_zipper_thread = NULL; - - zippoview->m_archive_name_view->SetText(" "); - zippoview->m_zip_output_view->SetText("Stopped"); - - CloseWindowOrKeepOpen(); + fZippingWasStopped = false; } + +void +ZippoWindow::_StopZipping() +{ + fZippingWasStopped = true; + + fView->fStopButton->SetEnabled(false); + fView->fActivityView->Stop(); + + fThread->InterruptExternalZip(); + fThread->Quit(); + + status_t status = B_OK; + fThread->WaitForThread(&status); + fThread = NULL; + + fView->fArchiveNameView->SetText(" "); + fView->fZipOutputView->SetText("Stopped"); + + _CloseWindowOrKeepOpen(); +} + + bool -ZippoWindow::IsZipping (void) +ZippoWindow::IsZipping() { - if (m_zipper_thread == NULL) + if (fThread == NULL) return false; else return true; } + void -ZippoWindow::CloseWindowOrKeepOpen (void) +ZippoWindow::_CloseWindowOrKeepOpen() { - if (m_got_refs_at_window_startup) + if (fWindowGotRefs) PostMessage(B_QUIT_REQUESTED); } + void -ZippoWindow::Zoom (BPoint origin, float width, float height) +ZippoWindow::Zoom(BPoint origin, float width, float height) { - /* - float archive_name_view_preferred_width; - float zip_output_view_preferred_width; - float throw_away_height; - zippoview->GetPreferredSize(& archive_name_view_preferred_width, & throw_away_height); - zippoview->GetPreferredSize(& zip_output_view_preferred_width, & throw_away_height); - */ - - // BStringView::GetPreferredSize appears to be broken, - // so we have to use BView::StringWidth() instead - - if (IsZipping()) - { - float archive_name_view_preferred_width = zippoview->StringWidth(zippoview->m_archive_name_view->Text()); - float zip_output_view_preferred_width = zippoview->StringWidth(zippoview->m_zip_output_view->Text()); + if (IsZipping()) { + float archiveNameWidth = + fView->StringWidth(fView->fArchiveNameView->Text()); + float zipOutputWidth = + fView->StringWidth(fView->fZipOutputView->Text()); - float the_wide_string; - - if (zip_output_view_preferred_width > archive_name_view_preferred_width) - the_wide_string = zip_output_view_preferred_width; + if (zipOutputWidth > archiveNameWidth) + ResizeTo(zipOutputWidth, Bounds().Height()); else - the_wide_string = archive_name_view_preferred_width; + ResizeTo(archiveNameWidth, Bounds().Height()); - ResizeTo(the_wide_string, Bounds().Height()); - } - else - { + } else { ResizeTo(230,110); } } diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h index d7cfaefb80..2876b3b6ce 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h @@ -1,46 +1,48 @@ -#ifndef __ZIPPO_WINDOW_H__ -#define __ZIPPO_WINDOW_H__ +#ifndef _ZIPOMATIC_WINDOW_H +#define _ZIPOMATIC_WINDOW_H + -#include -#include #include #include +#include #include +#include #include "ZipOMaticSettings.h" -class ZippoView; -class ZipperThread; +#include "ZipOMaticView.h" +#include "ZipperThread.h" + class ZippoWindow : public BWindow { public: - ZippoWindow (BMessage * a_message = NULL); - ~ZippoWindow (void); - virtual void MessageReceived (BMessage * a_message); - virtual bool QuitRequested (void); - virtual void Zoom (BPoint origin, float width, float height); + ZippoWindow(BMessage* message = NULL); + ~ZippoWindow(); + + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); + virtual void Zoom(BPoint origin, float width, float height); - bool IsZipping (void); - -private: + bool IsZipping(); - status_t ReadSettings (void); - status_t WriteSettings (void); +private: + status_t _ReadSettings(); + status_t _WriteSettings(); - void StartZipping (BMessage * a_message); - void StopZipping (void); - - void CloseWindowOrKeepOpen (void); + void _StartZipping(BMessage* message); + void _StopZipping(); + + void _CloseWindowOrKeepOpen(); - ZippoView * zippoview; - ZippoSettings m_zippo_settings; - ZipperThread * m_zipper_thread; + ZippoView* fView; + ZippoSettings fSettings; + ZipperThread* fThread; - bool m_got_refs_at_window_startup; - bool m_zipping_was_stopped; - - BMessage * m_alert_invoker_message; - BInvoker * m_alert_window_invoker; + bool fWindowGotRefs; + bool fZippingWasStopped; + + BInvoker* fWindowInvoker; }; -#endif // __ZIPPO_WINDOW_H__ +#endif // _ZIPOMATIC_WINDOW_H + diff --git a/src/add-ons/tracker/zipomatic/ZipperThread.cpp b/src/add-ons/tracker/zipomatic/ZipperThread.cpp index de17966a22..530ca2b769 100644 --- a/src/add-ons/tracker/zipomatic/ZipperThread.cpp +++ b/src/add-ons/tracker/zipomatic/ZipperThread.cpp @@ -23,7 +23,7 @@ #include "ZipOMaticWindow.h" -ZipperThread::ZipperThread (BMessage* refsMessage, BWindow* window) +ZipperThread::ZipperThread(BMessage* refsMessage, BWindow* window) : GenericThread("ZipperThread", B_NORMAL_PRIORITY, refsMessage), fWindowMessenger(window), @@ -61,7 +61,7 @@ ZipperThread::ThreadStartup() if (status != B_OK) return status; - for (int index = 0; index < refCount; index++) { + for (int index = 0; index < refCount; index++) { fThreadDataStore->FindRef("refs", index, &ref); if (index > 0) { @@ -109,7 +109,7 @@ ZipperThread::ThreadStartup() argv[2] = strdup(archiveName.String()); // files to zip - for (int index = 0; index < refCount; index++) { + for (int index = 0; index < refCount; index++) { fThreadDataStore->FindRef("refs", index, &ref); if (sameFolder) { @@ -190,7 +190,7 @@ ZipperThread::ThreadShutdown() void ZipperThread::ThreadStartupFailed(status_t status) { - error_message("ZipperThread::ThreadStartupFailed() \n", status); + ErrorMessage("ZipperThread::ThreadStartupFailed() \n", status); Quit(); } @@ -198,7 +198,7 @@ ZipperThread::ThreadStartupFailed(status_t status) void ZipperThread::ExecuteUnitFailed(status_t status) { - error_message("ZipperThread::ExecuteUnitFailed() \n", status); + ErrorMessage("ZipperThread::ExecuteUnitFailed() \n", status); if (status == EOF) { // thread has finished, been quit or killed, we don't know @@ -215,7 +215,7 @@ ZipperThread::ExecuteUnitFailed(status_t status) void ZipperThread::ThreadShutdownFailed(status_t status) { - error_message("ZipperThread::ThreadShutdownFailed() \n", status); + ErrorMessage("ZipperThread::ThreadShutdownFailed() \n", status); }