~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** main.cpp - initialization and profile/settings handling
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
5
** This program is free software; you can redistribute it and/or
 
6
** modify it under the terms of the GNU General Public License
 
7
** as published by the Free Software Foundation; either version 2
 
8
** of the License, or (at your option) any later version.
 
9
**
 
10
** This program is distributed in the hope that it will be useful,
 
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
** GNU General Public License for more details.
 
14
**
 
15
** You should have received a copy of the GNU General Public License
 
16
** along with this program; if not, write to the Free Software
 
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include"main.h"
 
22
 
 
23
#include<qapplication.h>
 
24
#include<qtimer.h>
 
25
#include<qimage.h>
 
26
#include<qbitmap.h>
 
27
#include<qtextcodec.h>
 
28
#include"common.h"
 
29
#include"jabcon.h"
 
30
#include"profiles.h"
 
31
#include"eventdlg.h"
 
32
#include"chatdlg.h"
 
33
#include"profiledlg.h"
 
34
 
 
35
 
 
36
QTranslator *trans;
 
37
QString curLang = "en";
 
38
QString curLangName = QT_TR_NOOP("language_name");
 
39
 
 
40
void setLang(const QString &lang)
 
41
{
 
42
        //printf("changing lang: [%s]\n", lang.latin1());
 
43
        trans->clear();
 
44
        if(lang == "en") {
 
45
                curLang = lang;
 
46
                curLangName = "English";
 
47
                return;
 
48
        }
 
49
 
 
50
        QStringList dirs;
 
51
        QString subdir = "";
 
52
        dirs += "." + subdir;
 
53
        dirs += g.pathHome + subdir;
 
54
        dirs += g.pathBase + subdir;
 
55
        for(QStringList::Iterator it = dirs.begin(); it != dirs.end(); ++it) {
 
56
                if(!QFile::exists(*it))
 
57
                        continue;
 
58
                if(trans->load("psi_" + lang, *it)) {
 
59
                        curLang = lang;
 
60
                        return;
 
61
                }
 
62
        }
 
63
}
 
64
 
 
65
 
 
66
static QColor configLoadColor(QSettings &settings, QString key, QString def)
 
67
{
 
68
        QColor c;
 
69
        c.setNamedColor(settings.readEntry(key, def));
 
70
        if(!c.isValid())
 
71
                c.setNamedColor(def);
 
72
 
 
73
        return c;
 
74
}
 
75
 
 
76
static QSize configLoadSize(QSettings &settings, QString key, QSize def)
 
77
{
 
78
        QStringList list = QStringList::split(',', settings.readEntry(key));
 
79
        if(list.count() != 2)
 
80
                return def;
 
81
 
 
82
        QSize s;
 
83
        s.setWidth(list[0].toInt());
 
84
        s.setHeight(list[1].toInt());
 
85
        return s;
 
86
}
 
87
 
 
88
static void folderkeyRemove(QSettings &settings, const QString &d)
 
89
{
 
90
        QStringList entries;
 
91
        QStringList::Iterator it;
 
92
 
 
93
        entries = settings.subkeyList(d);
 
94
        for(it = entries.begin(); it != entries.end(); ++it) {
 
95
                QString str = d + "/" + *it;
 
96
                folderkeyRemove(settings, str);
 
97
        }
 
98
 
 
99
        entries = settings.entryList(d);
 
100
        for(it = entries.begin(); it != entries.end(); ++it) {
 
101
                QString str = d + "/" + *it;
 
102
                settings.removeEntry(str);
 
103
        }
 
104
        settings.removeEntry(d);
 
105
}
 
106
 
 
107
 
 
108
PsiMain::PsiMain(QObject *par)
 
109
:QObject(par)
 
110
{
 
111
        j = 0;
 
112
 
 
113
        // detect available language packs
 
114
        langs.set("en", "English");
 
115
 
 
116
        QStringList dirs;
 
117
        QString subdir = "";
 
118
        dirs += "." + subdir;
 
119
        dirs += g.pathHome + subdir;
 
120
        dirs += g.pathBase + subdir;
 
121
 
 
122
        for(QStringList::Iterator it = dirs.begin(); it != dirs.end(); ++it) {
 
123
                if(!QFile::exists(*it))
 
124
                        continue;
 
125
                QDir d(*it);
 
126
                QStringList entries = d.entryList();
 
127
                for(QStringList::Iterator it2 = entries.begin(); it2 != entries.end(); ++it2) {
 
128
                        if(*it2 == "." || *it2 == "..")
 
129
                                continue;
 
130
 
 
131
                        QString str = *it2;
 
132
                        // verify that it is a language file
 
133
                        if(str.left(4) != "psi_")
 
134
                                continue;
 
135
                        int n = str.find('.', 4);
 
136
                        if(n == -1)
 
137
                                continue;
 
138
                        if(str.mid(n) != ".qm")
 
139
                                continue;
 
140
                        QString lang = str.mid(4, n-4);
 
141
 
 
142
                        //printf("found [%s], lang=[%s]\n", str.latin1(), lang.latin1());
 
143
 
 
144
                        // get the language_name
 
145
                        QString name = QString("[") + str + "]";
 
146
                        QTranslator t(0);
 
147
                        if(!t.load(str, *it))
 
148
                                continue;
 
149
 
 
150
                        if(t.contains("@default", "language_name", 0)) {
 
151
                                QString s = t.findMessage("@default", "language_name", 0).translation();
 
152
                                if(!s.isEmpty())
 
153
                                        name = s;
 
154
                        }
 
155
 
 
156
                        langs.set(lang, name);
 
157
                }
 
158
        }
 
159
 
 
160
        QSettings *s = new QSettings;
 
161
        s->insertSearchPath(QSettings::Windows, "/Affinix");
 
162
        s->insertSearchPath(QSettings::Unix, g.pathHome);
 
163
        lastProfile = s->readEntry("/psi/lastProfile");
 
164
        lastLang = s->readEntry("/psi/lastLang");
 
165
        autoOpen = s->readBoolEntry("/psi/autoOpen", FALSE);
 
166
        delete s;
 
167
 
 
168
        // get a debug window
 
169
        debug_window = new LogWindow;
 
170
 
 
171
        detectOldSettings();
 
172
 
 
173
        if(lastLang.isEmpty()) {
 
174
                lastLang = QTextCodec::locale();
 
175
                //printf("guessing locale: [%s]\n", lastLang.latin1());
 
176
        }
 
177
 
 
178
        setLang(lastLang);
 
179
 
 
180
        if(autoOpen)
 
181
                sessionStart(lastProfile);
 
182
        else
 
183
                QTimer::singleShot(0, this, SLOT(chooseProfile()));
 
184
}
 
185
 
 
186
PsiMain::~PsiMain()
 
187
{
 
188
        delete j;
 
189
 
 
190
        QSettings *s = new QSettings;
 
191
        s->insertSearchPath(QSettings::Windows, "/Affinix");
 
192
        s->insertSearchPath(QSettings::Unix, g.pathHome);
 
193
        s->writeEntry("/psi/lastProfile", lastProfile);
 
194
        s->writeEntry("/psi/lastLang", lastLang);
 
195
        s->writeEntry("/psi/autoOpen", autoOpen);
 
196
        delete s;
 
197
}
 
198
 
 
199
static bool loadGlobal()
 
200
{
 
201
        //QIconSet::setIconSize(QIconSet::Small, QSize(16,16));
 
202
        //QIconSet::setIconSize(QIconSet::Large, QSize(50,50));
 
203
 
 
204
        // set the paths
 
205
        g.pathBase = getResourcesDir();
 
206
        g.pathHome = getHomeDir();
 
207
        g.pathProfiles = g.pathHome + "/profiles";
 
208
 
 
209
        QDir d(g.pathProfiles);
 
210
        if(!d.exists()) {
 
211
                QDir d(g.pathHome);
 
212
                d.mkdir("profiles");
 
213
        }
 
214
 
 
215
        // load the graphics
 
216
        QStringList dirs;
 
217
        dirs += "./image";
 
218
        dirs += g.pathBase + "/image";
 
219
 
 
220
        pix_logo        = loadImage("psilogo.png", dirs);
 
221
        pix_main        = loadImage("psimain.png", dirs);
 
222
 
 
223
        pix_ssl_yes     = loadImage("ssl_yes.png", dirs);
 
224
        pix_ssl_no      = loadImage("ssl_no.png", dirs);
 
225
 
 
226
        //pixdat_ft_back   = loadImageData("ft_back.png", dirs, &pixlen_ft_back);
 
227
        //pixdat_ft_file   = loadImageData("ft_file.png", dirs, &pixlen_ft_file);
 
228
        //pixdat_ft_folder = loadImageData("ft_folder.png", dirs, &pixlen_ft_folder);
 
229
 
 
230
        pix_chatsend1 = 0;
 
231
        pix_chatsend2 = 0;
 
232
 
 
233
        QPixmap *tmp = loadImage("chatsend.png", dirs);
 
234
        if(tmp) {
 
235
                QImage image = tmp->convertToImage();
 
236
 
 
237
                QImage frame;
 
238
                frame = image.copy(0, 0, 50, 50);
 
239
                pix_chatsend1 = new QPixmap;
 
240
                pix_chatsend1->convertFromImage(frame);
 
241
                frame = image.copy(50, 0, 50, 50);
 
242
                pix_chatsend2 = new QPixmap;
 
243
                pix_chatsend2->convertFromImage(frame);
 
244
        }
 
245
 
 
246
        pix_chatclear = loadImage("chatclear.png", dirs);
 
247
        pix_account = loadImage("account.png", dirs);
 
248
        pix_icon_48 = loadImage("icon_48.png", dirs);
 
249
 
 
250
        uchar blank[] = {
 
251
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
252
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
253
        };
 
254
        QBitmap bm(16, 16, blank);
 
255
        pix_blank = new QPixmap(16,16);
 
256
        pix_blank->fill(Qt::black);
 
257
        pix_blank->setMask(bm);
 
258
 
 
259
        bool tic_ok = TRUE;
 
260
        QString tic_names[5] = { "trans", "icq", "aim", "msn", "yahoo" };
 
261
        QString tic_types[5] = { "offline", "online", "away", "xa", "dnd" };
 
262
        for(int n = 0; n < 5; ++n) {
 
263
                for(int n2 = 0; n2 < 5; ++n2) {
 
264
                        tic[n].p[n2] = loadImage(tic_names[n] + '_' + tic_types[n2] + ".png", dirs);
 
265
                        if(n == 0 && !tic[n].p[n2])
 
266
                                tic_ok = FALSE;
 
267
                }
 
268
        }
 
269
 
 
270
        if(!pix_logo || !pix_main || /*!pixdat_ft_back || !pixdat_ft_file || !pixdat_ft_folder ||*/
 
271
        !pix_chatsend1 || !pix_chatsend2 || !pix_chatclear || !pix_account || !tic_ok || !pix_ssl_yes || !pix_ssl_no || !pix_icon_48) {
 
272
                QMessageBox::critical(0, CAP(QObject::tr("Error")),QObject::tr(
 
273
                        "There were problems loading the images / icon set.  Be sure you have correctly installed Psi by\n"
 
274
                        "running the install script (\"./install\") after unpacking.  See the README for more details.\n"
 
275
                        ));
 
276
                return FALSE;
 
277
        }
 
278
 
 
279
        return TRUE;
 
280
}
 
281
 
 
282
void PsiMain::chooseProfile()
 
283
{
 
284
        if(j) {
 
285
                delete j;
 
286
                j = 0;
 
287
        }
 
288
 
 
289
        QString str = "";
 
290
 
 
291
        while(1) {
 
292
                ProfileOpenDlg *w = new ProfileOpenDlg(lastProfile, langs, curLang);
 
293
                w->ck_auto->setChecked(autoOpen);
 
294
                int r = w->exec();
 
295
                // lang change
 
296
                if(r == 10) {
 
297
                        QString newLang = w->newLang;
 
298
                        delete w;
 
299
                        setLang(newLang);
 
300
                        lastLang = curLang;
 
301
                        continue;
 
302
                }
 
303
                else {
 
304
                        if(r == QDialog::Accepted)
 
305
                                str = w->cb_profile->currentText();
 
306
                        autoOpen = w->ck_auto->isChecked();
 
307
                        delete w;
 
308
                        break;
 
309
                }
 
310
        }
 
311
 
 
312
        if(str.isEmpty()) {
 
313
                quit();
 
314
                return;
 
315
        }
 
316
 
 
317
        // only set lastProfile if the user opened it
 
318
        lastProfile = str;
 
319
        sessionStart(lastProfile);
 
320
}
 
321
 
 
322
bool PsiMain::sessionStart(const QString &str)
 
323
{
 
324
        //printf("starting session: [%s]\n", str.latin1());
 
325
 
 
326
        activeProfile = str;
 
327
 
 
328
        // get a jab console
 
329
        j = new jabcon(this);
 
330
        if(!j->init())
 
331
                return FALSE;
 
332
        connect(j, SIGNAL(quit(int)), SLOT(sessionQuit(int)));
 
333
 
 
334
        return TRUE;
 
335
}
 
336
 
 
337
void PsiMain::sessionQuit(int x)
 
338
{
 
339
        //printf("quit=%d\n", x);
 
340
        if(x == 0)
 
341
                QTimer::singleShot(0, this, SLOT(bail()));
 
342
        else if(x == 1)
 
343
                QTimer::singleShot(0, this, SLOT(chooseProfile()));
 
344
}
 
345
 
 
346
void PsiMain::bail()
 
347
{
 
348
        if(j) {
 
349
                delete j;
 
350
                j = 0;
 
351
        }
 
352
        quit();
 
353
}
 
354
 
 
355
void PsiMain::detectOldSettings()
 
356
{
 
357
        if(profileExists("Default"))
 
358
                return;
 
359
 
 
360
        QSettings settings;
 
361
        settings.insertSearchPath(QSettings::Windows, "/Affinix");
 
362
        settings.insertSearchPath(QSettings::Unix, g.pathHome);
 
363
 
 
364
        // try to determine if a version prior to 0.8.5 has been used
 
365
        if(settings.readNumEntry("/psi/winx", -100) == -100)
 
366
                return;
 
367
 
 
368
        int r = QMessageBox::information(0, CAP(tr("Old settings")),
 
369
                tr(
 
370
                "Old settings/history from a version of Psi prior to 0.8.5 have been detected.\n"
 
371
                "These will be imported into the \"Default\" profile.  Ok?"
 
372
                ),
 
373
                tr("Import"), tr("Skip"));
 
374
        if(r != 0)
 
375
                return;
 
376
 
 
377
        //printf("converting...\n");
 
378
 
 
379
        Options option;
 
380
        UserAccount acc;
 
381
        UserProfile pro;
 
382
 
 
383
        option = pro.prefs;
 
384
 
 
385
        acc.name = "Default";
 
386
 
 
387
        // gather up the old settings
 
388
        acc.user = settings.readEntry("/psi/username");
 
389
        acc.host = settings.readEntry("/psi/hostname");
 
390
        acc.pass = decodePassword(settings.readEntry("/psi/password"), QString("%1@%2").arg(acc.user).arg(acc.host));
 
391
        acc.port = settings.readNumEntry("/psi/port", 5222);
 
392
        acc.resource = settings.readEntry("/psi/resource", "Psi");
 
393
        acc.priority = settings.readNumEntry("/psi/priority", 0);
 
394
        acc.opt_auto = settings.readBoolEntry("/psi/opt_auto", FALSE);
 
395
        acc.opt_pass = settings.readBoolEntry("/psi/opt_pass", FALSE);
 
396
        acc.opt_ssl = settings.readBoolEntry("/psi/opt_ssl", FALSE);
 
397
        acc.tog_offline = settings.readBoolEntry("/psi/tog_offline", TRUE);
 
398
        acc.tog_away = settings.readBoolEntry("/psi/tog_away", TRUE);
 
399
        acc.tog_agents  = settings.readBoolEntry("/psi/tog_agents", TRUE);
 
400
        acc.olr_string = settings.readEntry("/psi/OLR");
 
401
 
 
402
        int win_x, win_y, win_w, win_h;
 
403
        win_x = settings.readNumEntry("/psi/winx", 64);
 
404
        win_y = settings.readNumEntry("/psi/winy", 64);
 
405
        win_w = settings.readNumEntry("/psi/winw", 160);
 
406
        win_h = settings.readNumEntry("/psi/winh", 360);
 
407
        pro.mwgeom.setRect(win_x, win_y, win_w, win_h);
 
408
        pro.lastStatusString = settings.readEntry("/psi/lastStatusString");
 
409
        pro.useSound = settings.readBoolEntry("/psi/usesound", TRUE);
 
410
 
 
411
        // get roster list
 
412
        QStringList entries = settings.subkeyList("/psi/roster");
 
413
        for(QStringList::Iterator i = entries.begin(); i != entries.end(); ++i) {
 
414
                QString jid = jidDecode(*i);
 
415
                JabRosterEntry *item = acc.roster.findByJid(jid);
 
416
                if(!item) {
 
417
                        item = new JabRosterEntry;
 
418
                        item->jid = cleanJid(jid);
 
419
                        acc.roster.add(item);
 
420
                }
 
421
 
 
422
                item->nick = settings.readEntry("/psi/roster/" + *i + "/nick");
 
423
                item->groups = settings.readListEntry("/psi/roster/" + *i + "/group");
 
424
                item->sub = settings.readEntry("/psi/roster/" + *i + "/sub");
 
425
        }
 
426
 
 
427
        // options
 
428
        option.useleft           = settings.readBoolEntry("/psi/options/general/roster/useleft", FALSE);
 
429
        option.singleclick       = settings.readBoolEntry("/psi/options/general/roster/singleclick", FALSE);
 
430
        option.defaultAction     = settings.readNumEntry("/psi/options/general/roster/defaultAction", 0);
 
431
        option.outgoingAs        = settings.readNumEntry("/psi/options/events/send/outgoingAs", 0);
 
432
 
 
433
        option.delChats          = settings.readNumEntry("/psi/options/general/misc/delChats", dcHour);
 
434
        option.browser           = settings.readNumEntry("/psi/options/general/misc/browser", 0);
 
435
        option.customBrowser     = settings.readEntry("/psi/options/general/misc/customBrowser");
 
436
        option.customMailer      = settings.readEntry("/psi/options/general/misc/customMailer");
 
437
 
 
438
#if defined(Q_WS_WIN)
 
439
        option.useDock           = settings.readBoolEntry("/psi/options/general/dock/useDock", TRUE);
 
440
        option.dockDCstyle       = settings.readBoolEntry("/psi/options/general/dock/dockDCstyle", TRUE);
 
441
        option.alwaysOnTop       = settings.readBoolEntry("/psi/options/general/misc/alwaysOnTop", TRUE);
 
442
#elif defined(Q_WS_X11)
 
443
        option.useDock           = settings.readBoolEntry("/psi/options/general/dock/useDock", FALSE);
 
444
        option.dockDCstyle       = settings.readBoolEntry("/psi/options/general/dock/dockDCstyle", FALSE);
 
445
        option.alwaysOnTop       = settings.readBoolEntry("/psi/options/general/misc/alwaysOnTop", FALSE);
 
446
#else
 
447
        option.useDock = FALSE;
 
448
        option.dockDCstyle = FALSE;
 
449
        option.alwaysOnTop = FALSE;
 
450
#endif
 
451
 
 
452
        option.keepSizes         = settings.readBoolEntry("/psi/options/general/misc/keepSizes", FALSE);
 
453
        option.ignoreHeadline    = settings.readBoolEntry("/psi/options/general/misc/ignoreHeadline", FALSE);
 
454
        option.sizeEventDlg      = configLoadSize(settings, "/psi/options/sizes/eventdlg", EventDlg::defaultSize());
 
455
        option.sizeChatDlg       = configLoadSize(settings, "/psi/options/sizes/chatdlg", ChatDlg::defaultSize());
 
456
 
 
457
        acc.opt_keepAlive         = settings.readBoolEntry("/psi/options/general/misc/keepAlive", TRUE);
 
458
        option.askOnline         = settings.readBoolEntry("/psi/options/presence/misc/askOnline", FALSE);
 
459
        option.rosterAnim        = settings.readBoolEntry("/psi/options/presence/misc/rosterAnim", TRUE);
 
460
        option.popupMsgs         = settings.readBoolEntry("/psi/options/events/receive/popupMsgs", FALSE);
 
461
        option.popupChats        = settings.readBoolEntry("/psi/options/events/receive/popupChats", FALSE);
 
462
        option.raise             = settings.readBoolEntry("/psi/options/events/receive/raise", FALSE);
 
463
        option.incomingAs        = settings.readNumEntry("/psi/options/events/receive/incomingAs", 0);
 
464
 
 
465
        option.onevent[eMessage] = settings.readEntry("/psi/options/events/onevent/message", option.onevent[eMessage]);
 
466
        option.onevent[eChat1]    = settings.readEntry("/psi/options/events/onevent/chat1", option.onevent[eChat1]);
 
467
        option.onevent[eChat2]    = settings.readEntry("/psi/options/events/onevent/chat2", option.onevent[eChat2]);
 
468
        option.onevent[eSystem]     = settings.readEntry("/psi/options/events/onevent/system", option.onevent[eSystem]);
 
469
        option.onevent[eOnline]  = settings.readEntry("/psi/options/events/onevent/online", option.onevent[eOnline]);
 
470
        option.onevent[eOffline]  = settings.readEntry("/psi/options/events/onevent/offline", option.onevent[eOffline]);
 
471
        option.onevent[eSend]    = settings.readEntry("/psi/options/events/onevent/send", option.onevent[eSend]);
 
472
 
 
473
        option.color[cOnline]    = configLoadColor(settings, "/psi/options/lookandfeel/colors/online",    "#0060C0");
 
474
        option.color[cListBack]  = configLoadColor(settings, "/psi/options/lookandfeel/colors/listback",  "#C0C0C0");
 
475
        option.color[cAway]      = configLoadColor(settings, "/psi/options/lookandfeel/colors/away",      "#008080");
 
476
        option.color[cDND]       = configLoadColor(settings, "/psi/options/lookandfeel/colors/dnd",       "#800000");
 
477
        option.color[cOffline]   = configLoadColor(settings, "/psi/options/lookandfeel/colors/offline",   "#000000");
 
478
        option.color[cGroupFore] = configLoadColor(settings, "/psi/options/lookandfeel/colors/groupfore", "#000000");
 
479
        option.color[cGroupBack] = configLoadColor(settings, "/psi/options/lookandfeel/colors/groupback", "#FFFFFF");
 
480
        option.font[fRoster]     = settings.readEntry("/psi/options/lookandfeel/fonts/roster", QApplication::font().toString());
 
481
        option.font[fMessage]    = settings.readEntry("/psi/options/lookandfeel/fonts/message", QApplication::font().toString());
 
482
        option.font[fChat]       = settings.readEntry("/psi/options/lookandfeel/fonts/chat", QApplication::font().toString());
 
483
        option.iconset           = "stellar"; //settings.readEntry("/psi/options/lookandfeel/iconset", "stellar");
 
484
        option.alertStyle        = settings.readNumEntry("/psi/options/events/alertstyle", 2);
 
485
 
 
486
        option.asAway            = settings.readNumEntry("/psi/options/presence/autostatus/away", 10);
 
487
        option.asXa              = settings.readNumEntry("/psi/options/presence/autostatus/xa", 30);
 
488
        option.asOffline         = settings.readNumEntry("/psi/options/presence/autostatus/offline", 0);
 
489
 
 
490
        QStringList vars         = settings.readListEntry("/psi/options/presence/statuspresets/vars");
 
491
        QStringList vals         = settings.readListEntry("/psi/options/presence/statuspresets/vals");
 
492
 
 
493
        QStringList::ConstIterator i1 = vars.begin();
 
494
        QStringList::ConstIterator i2 = vals.begin();
 
495
        for(; i1 != vars.end(); ++i1, ++i2)
 
496
                option.sp.set(*i1, *i2);
 
497
 
 
498
        option.player = settings.readEntry("/psi/options/sound/player", "play");
 
499
        option.noAwaySound = settings.readBoolEntry("/psi/options/sound/noawaysound", FALSE);
 
500
 
 
501
        // nuke the old
 
502
        settings.removeEntry("/psi/username");
 
503
        settings.removeEntry("/psi/hostname");
 
504
        settings.removeEntry("/psi/password");
 
505
        settings.removeEntry("/psi/port");
 
506
        settings.removeEntry("/psi/resource");
 
507
        settings.removeEntry("/psi/priority");
 
508
        settings.removeEntry("/psi/opt_auto");
 
509
        settings.removeEntry("/psi/opt_pass");
 
510
        settings.removeEntry("/psi/opt_ssl");
 
511
        settings.removeEntry("/psi/winx");
 
512
        settings.removeEntry("/psi/winy");
 
513
        settings.removeEntry("/psi/winw");
 
514
        settings.removeEntry("/psi/winh");
 
515
        settings.removeEntry("/psi/tog_offline");
 
516
        settings.removeEntry("/psi/tog_away");
 
517
        settings.removeEntry("/psi/tog_agents");
 
518
        settings.removeEntry("/psi/OLR");
 
519
        settings.removeEntry("/psi/lastStatusString");
 
520
        settings.removeEntry("/psi/usesound");
 
521
        folderkeyRemove(settings, "/psi/roster");
 
522
        folderkeyRemove(settings, "/psi/options");
 
523
 
 
524
        // save it
 
525
        pro.acc.append(acc);
 
526
        pro.prefs = option;
 
527
 
 
528
        bool ok = FALSE;
 
529
        if(profileNew("Default")) {
 
530
                if(pro.toFile(pathToProfileConfig("Default")))
 
531
                        ok = TRUE;
 
532
        }
 
533
 
 
534
        if(!ok) {
 
535
                QMessageBox::information(0, CAP(tr("Old settings")),
 
536
                        tr("There was an error creating a profile based on the old settings")
 
537
                        );
 
538
                return;
 
539
        }
 
540
 
 
541
        // move the history
 
542
        QDir fromDir, toDir;
 
543
        toDir.setPath(pathToProfile("Default") + "/history");
 
544
#ifdef Q_WS_X11
 
545
        fromDir.setPath(g.pathHome);
 
546
#else
 
547
        fromDir.setPath(".");
 
548
#endif
 
549
        entries = fromDir.entryList();
 
550
        for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
 
551
                if(*it == "." || *it == "..")
 
552
                        continue;
 
553
                QFileInfo info(fromDir, *it);
 
554
                if(info.isDir())
 
555
                        continue;
 
556
                if(info.extension(FALSE) != "history")
 
557
                        continue;
 
558
 
 
559
                QString src = info.filePath();
 
560
                QString dest = toDir.filePath(*it);
 
561
                //printf("[%s] -> [%s]\n", src.latin1(), dest.latin1());
 
562
                fileCopy(src, dest);
 
563
                fromDir.remove(info.filePath());
 
564
        }
 
565
}
 
566
 
 
567
int main(int argc, char *argv[])
 
568
{
 
569
        QApplication::addLibraryPath(getResourcesDir());
 
570
        QApplication *app = new QApplication(argc, argv);
 
571
 
 
572
        if(!loadGlobal())
 
573
                return 0;
 
574
 
 
575
        // japanese
 
576
        trans = new QTranslator(0);
 
577
        app->installTranslator(trans);
 
578
 
 
579
        PsiMain *psi = new PsiMain;
 
580
        QObject::connect(psi, SIGNAL(quit()), app, SLOT(quit()));
 
581
        app->exec();
 
582
        delete psi;
 
583
 
 
584
        return 0;
 
585
}