1 /* 2 * Copyright 2002-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Jerome Duval (jerome.duval@free.fr) 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11 #include "BackgroundsView.h" 12 13 #include <Application.h> 14 #include <TrackerAddOn.h> 15 #include <Window.h> 16 17 18 static const char *kSignature = "application/x-vnd.Haiku-Backgrounds"; 19 20 21 class BackgroundsApplication : public BApplication { 22 public: 23 BackgroundsApplication(); 24 virtual void RefsReceived(BMessage* message); 25 }; 26 27 class BackgroundsWindow : public BWindow { 28 public: 29 BackgroundsWindow(BRect frame, bool standalone = true); 30 31 void ProcessRefs(entry_ref dir, BMessage* refs); 32 33 protected: 34 virtual bool QuitRequested(); 35 virtual void WorkspaceActivated(int32 oldWorkspaces, bool active); 36 37 BackgroundsView *fBackgroundsView; 38 bool fIsStandalone; 39 }; 40 41 42 // #pragma mark - 43 44 45 BackgroundsApplication::BackgroundsApplication() 46 : BApplication(kSignature) 47 { 48 BWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325)); 49 window->Show(); 50 } 51 52 53 void 54 BackgroundsApplication::RefsReceived(BMessage* message) 55 { 56 if (CountWindows() > 0) { 57 BWindow* window = WindowAt(0); 58 BMessenger(window->ChildAt(0)).SendMessage(message); 59 } 60 61 } 62 63 // #pragma mark - 64 65 66 BackgroundsWindow::BackgroundsWindow(BRect frame, bool standalone) 67 : BWindow(frame, "Backgrounds", B_TITLED_WINDOW, 68 B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES), 69 fIsStandalone(standalone) 70 { 71 fBackgroundsView = new BackgroundsView(Bounds(), "BackgroundsView", 72 B_FOLLOW_ALL, B_WILL_DRAW); 73 AddChild(fBackgroundsView); 74 } 75 76 77 bool 78 BackgroundsWindow::QuitRequested() 79 { 80 fBackgroundsView->SaveSettings(); 81 if (fIsStandalone) 82 be_app->PostMessage(B_QUIT_REQUESTED); 83 84 return true; 85 } 86 87 88 void 89 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 90 { 91 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 92 } 93 94 95 void 96 BackgroundsWindow::ProcessRefs(entry_ref dir, BMessage* refs) 97 { 98 fBackgroundsView->ProcessRefs(dir, refs); 99 } 100 101 102 // #pragma mark - 103 104 105 /*! 106 \brief Tracker add-on entry 107 */ 108 void 109 process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/) 110 { 111 BackgroundsWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325), false); 112 window->ProcessRefs(dir, refs); 113 snooze(500); 114 window->Show(); 115 116 status_t status; 117 wait_for_thread(window->Thread(), &status); 118 } 119 120 121 int 122 main(int argc, char** argv) 123 { 124 BApplication* app = new BackgroundsApplication; 125 126 // This function doesn't return until the application quits 127 app->Run(); 128 delete app; 129 130 return 0; 131 } 132 133 134