This repository was archived by the owner on Mar 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQLSettings.cpp
More file actions
235 lines (193 loc) · 5.47 KB
/
QLSettings.cpp
File metadata and controls
235 lines (193 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright 2010-2024. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Humdinger, humdinger@mailbox.org
* Kevin Adams
* Chris Roberts
*/
#include "QLSettings.h"
#include "IgnoreListItem.h"
#include "QuickLaunch.h"
#include <Application.h>
#include <File.h>
#include <FindDirectory.h>
#include <Message.h>
#include <Path.h>
#include <Screen.h>
#include <stdio.h>
const char*
QLSettings::kDefaultSystemIgnore[] = {
"add-ons",
"bin",
"data",
"lib",
"servers",
"haiku_loader.bios_ia32",
"kernel_x86_64",
"runtime_loader",
NULL
};
QLSettings::QLSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return;
// Defaults
BScreen* screen = new BScreen(B_MAIN_SCREEN_ID);
BRect resolution = screen->Frame();
fMainWindowFrame = BRect(
resolution.Width() / 2 - 340.0 / 2, 100,
resolution.Width() / 2 + 340.0 / 2, 0);
delete screen;
fSetupWindowFrame = fMainWindowFrame.OffsetByCopy(70.0, 120.0);
fSetupWindowFrame.bottom = 770;
fDeskbar = false;
fShowVersion = fTempShowVersion = false;
fShowPath = fTempShowPath = true;
fSearchStart = fTempSearchStart = true;
fSaveSearch = false;
fSortFavorites = false;
fSearchTerm = "";
fShowIgnore = fTempApplyIgnore = true;
fFavoriteList = new BObjectList<entry_ref, true>();
fIgnoreList = new IgnoreListView();
path.Append("QuickLaunch_settings");
BFile file(path.Path(), B_READ_ONLY);
BMessage settings;
if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) {
BRect frame;
if (settings.FindRect("main window frame", &frame) == B_OK)
fMainWindowFrame = frame;
BRect setupframe;
if (settings.FindRect("setup window frame", &setupframe) == B_OK)
fSetupWindowFrame = setupframe;
int32 deskbar;
if (settings.FindInt32("deskbar", &deskbar) == B_OK)
fDeskbar = deskbar;
int32 version;
if (settings.FindInt32("show version", &version) == B_OK)
fShowVersion = fTempShowVersion = version;
int32 path;
if (settings.FindInt32("show path", &path) == B_OK)
fShowPath = fTempShowPath = path;
int32 searchstart;
if (settings.FindInt32("searchstart", &searchstart) == B_OK)
fSearchStart = fTempSearchStart = searchstart;
int32 savesearch;
if (settings.FindInt32("savesearch", &savesearch) == B_OK)
fSaveSearch = savesearch;
BString searchterm;
if (settings.FindString("searchterm", &searchterm) == B_OK)
fSearchTerm = searchterm;
int32 ignore;
if (settings.FindInt32("show ignore", &ignore) == B_OK)
fShowIgnore = fTempApplyIgnore = ignore;
int32 sortfavs;
if (settings.FindInt32("sort favorites", &sortfavs) == B_OK)
fSortFavorites = sortfavs;
}
}
QLSettings::~QLSettings()
{
delete fFavoriteList;
}
void
QLSettings::SaveSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
return;
BMessage settings;
settings.AddRect("main window frame", my_app->fMainWindow->Frame());
settings.AddRect("setup window frame", fSetupWindowFrame);
settings.AddInt32("deskbar", fDeskbar);
settings.AddInt32("show version", fShowVersion);
settings.AddInt32("show path", fShowPath);
settings.AddInt32("searchstart", fSearchStart);
settings.AddInt32("savesearch", fSaveSearch);
settings.AddString("searchterm", fSearchTerm);
settings.AddInt32("show ignore", fShowIgnore);
settings.AddInt32("sort favorites", fSortFavorites);
for (int32 i = 0; i < fIgnoreList->CountItems(); i++) {
IgnoreListItem* item = dynamic_cast<IgnoreListItem*>(fIgnoreList->ItemAt(i));
if (!item)
continue;
if (item->GetItem())
settings.AddString("item", item->GetItem());
}
for (int32 i = 0; i < fFavoriteList->CountItems(); i++) {
entry_ref* favorite = fFavoriteList->ItemAt(i);
if (!favorite)
continue;
BEntry entry(favorite);
if (entry.InitCheck() == B_OK) {
BPath path;
entry.GetPath(&path);
settings.AddString("favorite", path.Path());
}
}
path.Append("QuickLaunch_settings");
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() == B_OK)
settings.Flatten(&file);
}
void
QLSettings::InitLists()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return;
path.Append("QuickLaunch_settings");
BFile file(path.Path(), B_READ_ONLY);
BMessage settings;
if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) {
BString itemText;
int32 i = 0;
while (settings.FindString("item", i++, &itemText) == B_OK) {
fIgnoreList->AddItem(new IgnoreListItem(itemText.String()));
}
i = 0;
while (settings.FindString("favorite", i++, &itemText) == B_OK) {
entry_ref favorite;
get_ref_for_path(itemText.String(), &favorite);
BEntry entry(&favorite);
if (entry.Exists())
fFavoriteList->AddItem(new entry_ref(favorite));
}
} else // First launch? Add default ignore items
AddDefaultIgnore();
}
void
QLSettings::AddDefaultIgnore()
{
BPath systemDir;
if (find_directory(B_SYSTEM_DIRECTORY, &systemDir) != B_OK)
return;
int32 count = fIgnoreList->CountItems();
for (const char** list = kDefaultSystemIgnore; *list != NULL; ++list) {
bool inList = false;
BString dir = systemDir.Path();
dir << "/" << *list;
for (int i = 0; i < count; i++) {
IgnoreListItem* item = dynamic_cast<IgnoreListItem*>(fIgnoreList->ItemAt(i));
if (strcasecmp(dir.String(), item->GetItem()) == 0) {
inList = true;
break;
}
}
if (!inList)
fIgnoreList->AddItem(new IgnoreListItem(dir));
}
}
bool
QLSettings::Lock()
{
return fLock.Lock();
}
void
QLSettings::Unlock()
{
fLock.Unlock();
}