repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / launchbox / App.cpp
blobfcf5447852a0701576df44c8841cc4c7d6ca2835
1 /*
2 * Copyright 2006-2011, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "App.h"
8 #include <stdio.h>
10 #include <Catalog.h>
11 #include <Entry.h>
12 #include <Message.h>
13 #include <String.h>
15 #include "support.h"
17 #include "MainWindow.h"
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "LaunchBox"
22 App::App()
24 BApplication("application/x-vnd.Haiku-LaunchBox"),
25 fSettingsChanged(false),
26 fNamePanelSize(200, 50)
28 SetPulseRate(3000000);
32 App::~App()
37 bool
38 App::QuitRequested()
40 _StoreSettingsIfNeeded();
41 return true;
45 void
46 App::ReadyToRun()
48 bool windowAdded = false;
49 BRect frame(50.0, 50.0, 65.0, 100.0);
51 BMessage settings;
52 status_t status = load_settings(&settings, "main_settings", "LaunchBox");
53 if (status >= B_OK) {
54 BMessage windowMessage;
55 for (int32 i = 0; settings.FindMessage("window", i, &windowMessage)
56 >= B_OK; i++) {
57 BString string;
58 string << i + 1;
59 BString name(B_TRANSLATE("Pad %1"));
60 name.ReplaceFirst("%1", string);
61 BMessage* windowSettings = new BMessage(windowMessage);
62 MainWindow* window = new MainWindow(name.String(), frame,
63 windowSettings);
64 window->Show();
65 windowAdded = true;
66 frame.OffsetBy(10.0, 10.0);
67 windowMessage.MakeEmpty();
69 BSize size;
70 if (settings.FindSize("name panel size", &size) == B_OK)
71 fNamePanelSize = size;
74 if (!windowAdded) {
75 MainWindow* window = new MainWindow(B_TRANSLATE("Pad 1"), frame, true);
76 window->Show();
81 void
82 App::MessageReceived(BMessage* message)
84 switch (message->what) {
85 case MSG_ADD_WINDOW: {
86 BMessage* settings = new BMessage('sett');
87 bool wasCloned = message->FindMessage("window", settings) == B_OK;
88 BString string;
89 string << CountWindows() + 1;
90 BString name(B_TRANSLATE("Pad %1"));
91 name.ReplaceFirst("%1", string);
92 MainWindow* window = new MainWindow(name.String(),
93 BRect(50.0, 50.0, 65.0, 100.0), settings);
94 if (wasCloned)
95 window->MoveBy(10, 10);
96 window->Show();
97 fSettingsChanged = true;
98 break;
100 case MSG_SETTINGS_CHANGED:
101 fSettingsChanged = true;
102 break;
103 default:
104 BApplication::MessageReceived(message);
105 break;
110 void
111 App::Pulse()
113 _StoreSettingsIfNeeded();
117 void
118 App::SetNamePanelSize(const BSize& size)
120 if (Lock()) {
121 fNamePanelSize = size;
122 Unlock();
127 BSize
128 App::NamePanelSize()
130 BSize size;
131 if (Lock()) {
132 size = fNamePanelSize;
133 Unlock();
135 return size;
139 void
140 App::_StoreSettingsIfNeeded()
142 if (!fSettingsChanged)
143 return;
145 BMessage settings('sett');
146 for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
147 if (MainWindow* padWindow = dynamic_cast<MainWindow*>(window)) {
148 if (padWindow->Lock()) {
149 BMessage* windowSettings = padWindow->Settings();
150 if (windowSettings) {
151 padWindow->SaveSettings(windowSettings);
152 settings.AddMessage("window", windowSettings);
154 padWindow->Unlock();
158 settings.AddSize("name panel size", fNamePanelSize);
160 save_settings(&settings, "main_settings", "LaunchBox");
162 fSettingsChanged = false;