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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/*
* Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "math.h"
#include "main.h"
using namespace std;
#define _P(x) wx2std(x)
std::string wx2std (const wxString & input)
{
int size = input.Length () + 1; // will be big enough
char *buffer = new char[size];
wxEncodingConverter wxec;
wxec.Init (wxFONTENCODING_UNICODE, wxFONTENCODING_ISO8859_1);
wxec.Convert (input.wc_str (wxConvUTF8), buffer);
std::string temp (buffer);
delete [] buffer;
return temp;
}
string
getGTKIconPath(string name) {
GtkIconInfo *iconInfo = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default(),
name.c_str(), // icon name
48,
GTK_ICON_LOOKUP_FORCE_SIZE);
const char *filename;
if (iconInfo != NULL) {
return gtk_icon_info_get_filename (iconInfo);
}
return string("");
}
IMPLEMENT_APP (MyApp)
int startPositionX = 50;
int startPositionY = 50;
wxString dirPath;
wxString markPath = _T (DATA_DIR "/mark.png");
wxString questionPath = _T (DATA_DIR "/question.png");
bool
loadSettings (simSettings* settings)
{
simGconf_loadSettings (settings);
simGconf_loadPosition (&startPositionX, &startPositionY);
settings->MAXSIZE = (int)(settings->ICONH + (settings->ICONH * ((double)settings->PERCENT / 100)));
return TRUE;
}
bool
loadPrograms (wxString fullPath, ImagesArray * list,simSettings* settings, string defaultLaunchers)
{
openOrInitialize (&fullPath, &defaultLaunchers);
wxXmlDocument doc;
if (!doc.Load (fullPath))
{
exit (1);
return FALSE;
}
// start processing the XML file
if (doc.GetRoot ()->GetName () != wxT (XML_PROGRAM))
{
cout << "invalid xml file" << endl;
return FALSE;
}
wxXmlNode *program = doc.GetRoot ()->GetChildren ();
int id = 0;
while (program)
{
if (program->GetName () == wxT (XML_SIMDOCK))
{
wxXmlNode *child = program->GetChildren ();
wxString path, icon, descr, name;
while (child)
{
if (child->GetName () == wxT (XML_PATH))
path = child->GetNodeContent ();
if (child->GetName () == wxT (XML_ICON))
icon = child->GetNodeContent ();
if (child->GetName () == wxT (XML_DESCR))
descr = child->GetNodeContent ();
if (child->GetName () == wxT (XML_NAME))
name = child->GetNodeContent ();
child = child->GetNext ();
}
if (!path.IsEmpty () && !icon.IsEmpty ())
{
wxImage img;
if (!img.LoadFile (icon))
{
img.LoadFile(questionPath);
}
simImage *sim = new simImage (img,
icon,
path,
name,
descr,
id++);
sim->w = settings->ICONW;
sim->h = settings->ICONH;
sim->y = (settings->MAXSIZE + settings->BOTTOM_BORDER) - settings->ICONH - settings->BOTTOM_BORDER; // I
// know,
// it's
// ugly
list->Add (sim);
#ifdef SIMDOCK_DEBUG
cout << id << ":" << wx2std (name) << endl;
#endif
}
}
program = program->GetNext ();
}
return TRUE;
}
void
loadAll (ImagesArray * list, simSettings* settings, string defaultLaunchers)
{
wxString home = wxGetHomeDir ();
if (home.IsEmpty ())
{
cout <<
"Could not determine user's home directory."
"\nplease set HOME environment variable"
<< endl;
exit (1);
}
dirPath = home + _T ("/") + _T (CONF_DIR);
if (!fixSimDir (&dirPath))
{
exit (1);
}
if (!loadSettings (settings))
{
exit (1);
}
if (!loadPrograms (PROGRAMS_PATH, list,settings, defaultLaunchers))
{
exit (1);
}
}
wxSize
PositionIcons (wxSize sz, simSettings settings, ImagesArray* ImagesList) {
int neededSpace = 0;
int availableSpace = settings.LEFT_BORDER;
for (unsigned int i = 0; i < ImagesList->GetCount (); i++) {
simImage *img = (*ImagesList)[i];
neededSpace += img->w + settings.SPACER;
availableSpace += settings.ICONW + settings.SPACER;
}
availableSpace += settings.RIGHT_BORDER - settings.SPACER;
neededSpace -= settings.SPACER;
double ratio = (double)settings.LEFT_BORDER / (settings.LEFT_BORDER + settings.RIGHT_BORDER);
int positionX = (availableSpace - neededSpace) * ratio;
for (unsigned int i = 0; i < ImagesList->GetCount (); i++) {
simImage *img = (*ImagesList)[i];
img->x = positionX;
positionX += img->w + settings.SPACER;
}
return wxSize (availableSpace, settings.MAXSIZE);
}
wxSize
FirstPosition (wxSize sz, simSettings settings, ImagesArray* list)
{
return PositionIcons (sz, settings,list);
}
void
MyApp::GracefullyExit () {
if (!frame) {
cout << "GracefullyExit: Null Frame!!" << endl;
return;
}
if (!frame->disposed) {
simGconf_savePosition (frame->GetPosition ().x, frame->GetPosition ().y);
} else {
simGconf_savePosition (frame->lastPosition.x, frame->lastPosition.y);
}
}
int
MyApp::OnExit ()
{
GracefullyExit ();
return 0; // Reference sais this is ignored..
}
bool
MyApp::OnInit () {
if (!wxApp::OnInit ()) { return false; }
string filepath = getGTKIconPath("firefox");
defaultLaunchers = "<Program>\n"
"<SimDock>\n"
"</SimDock>\n"
"</Program>\n";
if (filepath != "") {
defaultLaunchers = "<Program>\n"
"<SimDock>\n"
"<path>/usr/bin/firefox</path>\n"
"<icon>" + getGTKIconPath("firefox") + "</icon>\n"
"<description>Firefox web browser</description>\n"
"<name>Firefox</name>\n" "</SimDock>\n" "</Program>\n";
}
ImagesList = new ImagesArray ();
wxInitAllImageHandlers ();
//default values
simSettings settings = {
30, // LEFT_BORDER,
30, //RIGHT_BORDER,
15, // BOTTOM_BORDER,
30, //ICONW,
30, //ICONH,
50, //PERCENT,
90, // RANGE,
8, // SPACER,
30, // BG_HEIGHT,
5, // REFLEX_SCALING,
100, // REFLEX_ALPHA,
30, // MAXSIZE
50, //BLUR_TIMEOUT
_T (DATA_DIR "/bg5.png"), // bgPath,
true, // SHOW_REFLEXES,
true, // ENABLE_TASKS,
true, // ENABLE_MINIMIZE,
true //AUTO_POSITION
};
loadAll (ImagesList, & settings, defaultLaunchers);
long options = wxNO_BORDER;
options = options | wxFRAME_TOOL_WINDOW;
if (!showInTray)
{
options = options | wxFRAME_NO_TASKBAR;
}
if (onTop)
options = options | wxSTAY_ON_TOP;
frame = new MyFrame (NULL, settings,ImagesList,-1, _T ("SimDock"), wxPoint (10, 10),
wxSize (450, 150), options);
wxImage* appBackground = new wxImage (settings.BG_PATH);
appBackground->Rescale (frame->GetClientSize ().GetWidth(), settings.BG_HEIGHT, wxIMAGE_QUALITY_HIGH);
frame->SetBG(appBackground);
wxBitmap* bmp = new wxBitmap(wxImage (markPath));
frame->SetMarkBitmap(bmp);
frame->frameOptions = options;
frame->updateSize();
register_sigint (this); // CTRL-C Handling
frame->Show (TRUE);
frame->Freeze();
GtkWidget* widget = frame->GetHandle();
XID xid = GDK_WINDOW_XWINDOW(widget->window);
xstuff_resizeScreen(xid, *frame);
if (settings.ENABLE_TASKS)
{
tasks_fillList(ImagesList, settings);
tasks_register_signals(ImagesList, settings);
}
frame->appSize = FirstPosition (frame->GetClientSize (), settings, ImagesList);
frame->updateSize();
if (!settings.AUTO_POSITION)
{
frame->Move (startPositionX, startPositionY);
}
else
{
wxSize sz = wxGetDisplaySize();
frame->Move ((sz.GetWidth() - frame->GetClientSize().GetWidth()) / 2,
sz.GetHeight() - frame->GetClientSize().GetHeight());
}
//getting the background from root will only work at a late point
//like this
wxBitmap * backImage;
if (!customBackground.IsEmpty ())
{
backImage =
fixImage (customBackground, customBackgroundType,
customBackgroundColour);
}
else
{
backImage = getRootWallpaper();
}
frame->SetWallpaper(backImage);
//a dock should always be shown on all desktops by default
frame->Thaw();
xstuff_setDefaultWindowFlags(xid);
return TRUE;
}
|