1 /* 2 * Copyright 2002-2006, 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 }; 25 26 class BackgroundsWindow : public BWindow { 27 public: 28 BackgroundsWindow(BRect frame, bool standalone = true); 29 30 void ProcessRefs(entry_ref dir, BMessage* refs); 31 32 protected: 33 virtual bool QuitRequested(); 34 virtual void WorkspaceActivated(int32 oldWorkspaces, bool active); 35 36 BackgroundsView *fBackgroundsView; 37 bool fIsStandalone; 38 }; 39 40 41 // #pragma mark - 42 43 44 BackgroundsApplication::BackgroundsApplication() 45 : BApplication(kSignature) 46 { 47 BWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325)); 48 window->Show(); 49 } 50 51 52 // #pragma mark - 53 54 55 BackgroundsWindow::BackgroundsWindow(BRect frame, bool standalone) 56 : BWindow(frame, "Backgrounds", B_TITLED_WINDOW, 57 B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES), 58 fIsStandalone(standalone) 59 { 60 fBackgroundsView = new BackgroundsView(Bounds(), "BackgroundsView", 61 B_FOLLOW_ALL, B_WILL_DRAW); 62 fBackgroundsView->ResizeToPreferred(); 63 ResizeTo(fBackgroundsView->Bounds().Width(), fBackgroundsView->Bounds().Height()); 64 65 AddChild(fBackgroundsView); 66 67 // TODO: center on screen 68 // TODO: save window position? 69 } 70 71 72 bool 73 BackgroundsWindow::QuitRequested() 74 { 75 fBackgroundsView->SaveSettings(); 76 if (fIsStandalone) 77 be_app->PostMessage(B_QUIT_REQUESTED); 78 79 return true; 80 } 81 82 83 void 84 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 85 { 86 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 87 } 88 89 90 void 91 BackgroundsWindow::ProcessRefs(entry_ref dir, BMessage* refs) 92 { 93 fBackgroundsView->ProcessRefs(dir, refs); 94 } 95 96 97 // #pragma mark - 98 99 100 /*! 101 \brief Tracker add-on entry 102 */ 103 void 104 process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/) 105 { 106 BackgroundsWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325), false); 107 window->ProcessRefs(dir, refs); 108 snooze(500); 109 window->Show(); 110 111 status_t status; 112 wait_for_thread(window->Thread(), &status); 113 } 114 115 116 int 117 main(int argc, char** argv) 118 { 119 BApplication* app = new BackgroundsApplication; 120 121 // This function doesn't return until the application quits 122 app->Run(); 123 delete app; 124 125 return 0; 126 } 127 128 129