1 | #include "opt_iconset.h"
|
---|
2 | #include "common.h"
|
---|
3 | #include "iconwidget.h"
|
---|
4 | #include "psicon.h"
|
---|
5 |
|
---|
6 | #include <qbuttongroup.h>
|
---|
7 | #include <qwhatsthis.h>
|
---|
8 | #include <qcheckbox.h>
|
---|
9 | #include <qradiobutton.h>
|
---|
10 | #include <qcombobox.h>
|
---|
11 | #include <qlineedit.h>
|
---|
12 | #include <qfileinfo.h>
|
---|
13 | #include <qlistview.h>
|
---|
14 | #include <qheader.h>
|
---|
15 | #include <qapplication.h>
|
---|
16 | #include <qthread.h>
|
---|
17 | #include <qmutex.h>
|
---|
18 | #include <qevent.h>
|
---|
19 | #include <qprogressbar.h>
|
---|
20 | #include <qcursor.h>
|
---|
21 | #include <qpalette.h>
|
---|
22 | #include <qtabwidget.h>
|
---|
23 |
|
---|
24 | #include "opt_iconset_emo.h"
|
---|
25 | #include "opt_iconset_system.h"
|
---|
26 | #include "opt_iconset_roster.h"
|
---|
27 | #include "ui_isdetails.h"
|
---|
28 |
|
---|
29 | static void isDetails(const Iconset &is, QWidget *parent)
|
---|
30 | {
|
---|
31 | IconsetDetailsDlg *isd = new IconsetDetailsDlg(parent, "IconsetDetailsDlg", false, QWidget::WDestructiveClose);
|
---|
32 | isd->setIconset(is);
|
---|
33 | isd->show();
|
---|
34 | }
|
---|
35 |
|
---|
36 | static QStringList dirs;
|
---|
37 |
|
---|
38 | static int countIconsets(QString addDir, QStringList excludeList)
|
---|
39 | {
|
---|
40 | int count = 0;
|
---|
41 |
|
---|
42 | QStringList::Iterator it = dirs.begin();
|
---|
43 | for ( ; it != dirs.end(); ++it) {
|
---|
44 | QString fileName = *it + "/iconsets" + addDir;
|
---|
45 | QDir dir (fileName);
|
---|
46 |
|
---|
47 | QStringList list = dir.entryList("*");
|
---|
48 | QStringList::Iterator it2 = list.begin();
|
---|
49 | for ( ; it2 != list.end(); ++it2) {
|
---|
50 | if ( *it2 == "." || *it2 == ".." )
|
---|
51 | continue;
|
---|
52 |
|
---|
53 | bool found = false;
|
---|
54 | QStringList::Iterator it3 = excludeList.begin();
|
---|
55 | for ( ; it3 != excludeList.end(); ++it3) {
|
---|
56 | if ( *it2 == *it3 ) {
|
---|
57 | found = true;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | if ( found )
|
---|
63 | continue;
|
---|
64 |
|
---|
65 | count++;
|
---|
66 | excludeList << *it2;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | return count;
|
---|
71 | }
|
---|
72 |
|
---|
73 | //----------------------------------------------------------------------------
|
---|
74 | // IconsetLoadEvent
|
---|
75 | //----------------------------------------------------------------------------
|
---|
76 |
|
---|
77 | class IconsetLoadEvent : public QEvent
|
---|
78 | {
|
---|
79 | public:
|
---|
80 | IconsetLoadEvent(IconsetLoadThread *par, Iconset *i)
|
---|
81 | : QEvent(QEvent::User)
|
---|
82 | {
|
---|
83 | p = par;
|
---|
84 | is = i;
|
---|
85 | }
|
---|
86 |
|
---|
87 | IconsetLoadThread *thread() const { return p; }
|
---|
88 |
|
---|
89 | // if iconset() is '0' then it means that iconset wans't loaded successfully
|
---|
90 | Iconset *iconset() const { return is; }
|
---|
91 |
|
---|
92 | private:
|
---|
93 | IconsetLoadThread *p;
|
---|
94 | Iconset *is;
|
---|
95 | };
|
---|
96 |
|
---|
97 | //----------------------------------------------------------------------------
|
---|
98 | // IconsetFinishEvent
|
---|
99 | //----------------------------------------------------------------------------
|
---|
100 |
|
---|
101 | class IconsetFinishEvent : public QEvent
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | IconsetFinishEvent()
|
---|
105 | : QEvent( (QEvent::Type)(QEvent::User + 1) )
|
---|
106 | {
|
---|
107 | }
|
---|
108 | };
|
---|
109 |
|
---|
110 |
|
---|
111 | //----------------------------------------------------------------------------
|
---|
112 | // IconsetLoadThreadDestroyEvent
|
---|
113 | //----------------------------------------------------------------------------
|
---|
114 |
|
---|
115 | class IconsetLoadThreadDestroyEvent : public QEvent
|
---|
116 | {
|
---|
117 | public:
|
---|
118 | IconsetLoadThreadDestroyEvent(QThread *t)
|
---|
119 | : QEvent( (QEvent::Type)(QEvent::User + 2) )
|
---|
120 | {
|
---|
121 | thread = t;
|
---|
122 | }
|
---|
123 |
|
---|
124 | ~IconsetLoadThreadDestroyEvent()
|
---|
125 | {
|
---|
126 | thread->wait();
|
---|
127 | delete thread;
|
---|
128 | }
|
---|
129 |
|
---|
130 | private:
|
---|
131 | QThread *thread;
|
---|
132 | };
|
---|
133 |
|
---|
134 | //----------------------------------------------------------------------------
|
---|
135 | // IconsetLoadThread
|
---|
136 | //----------------------------------------------------------------------------
|
---|
137 |
|
---|
138 | class IconsetLoadThread : public QThread
|
---|
139 | {
|
---|
140 | public:
|
---|
141 | IconsetLoadThread(QObject *parent, QString addPath);
|
---|
142 | void excludeIconsets(QStringList);
|
---|
143 |
|
---|
144 | bool cancelled;
|
---|
145 |
|
---|
146 | protected:
|
---|
147 | void run();
|
---|
148 | void postEvent(QEvent *);
|
---|
149 |
|
---|
150 | private:
|
---|
151 | QObject *parent;
|
---|
152 | QString addPath;
|
---|
153 | QStringList excludeList;
|
---|
154 | };
|
---|
155 |
|
---|
156 | IconsetLoadThread::IconsetLoadThread(QObject *p, QString path)
|
---|
157 | {
|
---|
158 | cancelled = false;
|
---|
159 | parent = p;
|
---|
160 | addPath = path;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void IconsetLoadThread::excludeIconsets(QStringList l)
|
---|
164 | {
|
---|
165 | excludeList += l;
|
---|
166 | }
|
---|
167 |
|
---|
168 | static QMutex threadCancelled, threadMutex;
|
---|
169 |
|
---|
170 | void IconsetLoadThread::postEvent(QEvent *e)
|
---|
171 | {
|
---|
172 | threadCancelled.lock();
|
---|
173 | bool cancel = cancelled;
|
---|
174 | threadCancelled.unlock();
|
---|
175 |
|
---|
176 | if ( cancel ) {
|
---|
177 | delete e;
|
---|
178 | return;
|
---|
179 | }
|
---|
180 |
|
---|
181 | QApplication::postEvent(parent, e);
|
---|
182 | }
|
---|
183 |
|
---|
184 | void IconsetLoadThread::run()
|
---|
185 | {
|
---|
186 | threadMutex.lock();
|
---|
187 | QStringList dirs = ::dirs;
|
---|
188 | threadMutex.unlock();
|
---|
189 |
|
---|
190 | QStringList::Iterator it = dirs.begin();
|
---|
191 | for ( ; it != dirs.end(); ++it) {
|
---|
192 | QString fileName = *it + "/iconsets" + addPath;
|
---|
193 | QDir dir (fileName);
|
---|
194 |
|
---|
195 | QStringList list = dir.entryList("*");
|
---|
196 | QStringList::Iterator it2 = list.begin();
|
---|
197 | for ( ; it2 != list.end(); ++it2) {
|
---|
198 | if ( *it2 == "." || *it2 == ".." )
|
---|
199 | continue;
|
---|
200 |
|
---|
201 | threadCancelled.lock();
|
---|
202 | bool cancel = cancelled;
|
---|
203 | threadCancelled.unlock();
|
---|
204 |
|
---|
205 | if ( cancel )
|
---|
206 | goto getout;
|
---|
207 |
|
---|
208 | bool found = false;
|
---|
209 | QStringList::Iterator it3 = excludeList.begin();
|
---|
210 | for ( ; it3 != excludeList.end(); ++it3) {
|
---|
211 | if ( *it2 == *it3 ) {
|
---|
212 | found = true;
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | if ( found )
|
---|
218 | continue;
|
---|
219 |
|
---|
220 | IconsetLoadEvent *event = 0;
|
---|
221 | Iconset *is = new Iconset;
|
---|
222 |
|
---|
223 | if ( is->load (fileName + "/" + *it2) ) {
|
---|
224 | excludeList << *it2;
|
---|
225 |
|
---|
226 | // don't forget to delete iconset in ::event()!
|
---|
227 | event = new IconsetLoadEvent(this, is);
|
---|
228 | }
|
---|
229 | else {
|
---|
230 | delete is;
|
---|
231 | event = new IconsetLoadEvent(this, 0);
|
---|
232 |
|
---|
233 | // without excluding corrupted iconset,
|
---|
234 | // counter will go nuts! read more comments
|
---|
235 | // about that...
|
---|
236 | excludeList << *it2;
|
---|
237 | // TODO: there is possibility,
|
---|
238 | // that there's a bunch of same-named
|
---|
239 | // iconsets, and some of them are corrupted.
|
---|
240 | // It is possible to write a hack that
|
---|
241 | // loads iconset even in that case.
|
---|
242 |
|
---|
243 | // logic:
|
---|
244 | // tried to load iconset --> unable to load
|
---|
245 | // checking if there's same-named iconsets in
|
---|
246 | // other directories
|
---|
247 | // emit IconsetLoadEvent() only on success
|
---|
248 | // or when last corrupted iconset was unable
|
---|
249 | // to load
|
---|
250 | }
|
---|
251 |
|
---|
252 | postEvent(event);
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | getout:
|
---|
257 | postEvent(new IconsetFinishEvent());
|
---|
258 | QApplication::postEvent(qApp, new IconsetLoadThreadDestroyEvent(this)); // self destruct
|
---|
259 | }
|
---|
260 |
|
---|
261 | //----------------------------------------------------------------------------
|
---|
262 | // OptionsTabIconsetSystem
|
---|
263 | //----------------------------------------------------------------------------
|
---|
264 |
|
---|
265 | OptionsTabIconsetSystem::OptionsTabIconsetSystem(QObject *parent)
|
---|
266 | : OptionsTab(parent, "iconset_system", "", tr("System Icons"), tr("Select the system iconset"))
|
---|
267 | {
|
---|
268 | w = 0;
|
---|
269 | thread = 0;
|
---|
270 |
|
---|
271 | if ( dirs.isEmpty() ) {
|
---|
272 | dirs << ".";
|
---|
273 | dirs << g.pathHome;
|
---|
274 | dirs << g.pathBase;
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | OptionsTabIconsetSystem::~OptionsTabIconsetSystem()
|
---|
279 | {
|
---|
280 | cancelThread();
|
---|
281 | }
|
---|
282 |
|
---|
283 | QWidget *OptionsTabIconsetSystem::widget()
|
---|
284 | {
|
---|
285 | if ( w )
|
---|
286 | return 0;
|
---|
287 |
|
---|
288 | w = new IconsetSystemUI;
|
---|
289 | IconsetSystemUI *d = (IconsetSystemUI *)w;
|
---|
290 |
|
---|
291 | connect(d->pb_sysDetails, SIGNAL(clicked()), SLOT(previewIconset()));
|
---|
292 |
|
---|
293 | // TODO: add QWhatsThis
|
---|
294 |
|
---|
295 | return w;
|
---|
296 | }
|
---|
297 |
|
---|
298 | void OptionsTabIconsetSystem::applyOptions(Options *opt)
|
---|
299 | {
|
---|
300 | if ( !w || thread )
|
---|
301 | return;
|
---|
302 |
|
---|
303 | IconsetSystemUI *d = (IconsetSystemUI *)w;
|
---|
304 | const Iconset *is = d->iss_system->iconset();
|
---|
305 | if ( is ) {
|
---|
306 | QFileInfo fi( is->fileName() );
|
---|
307 | opt->systemIconset = fi.fileName();
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | void OptionsTabIconsetSystem::restoreOptions(const Options *opt)
|
---|
312 | {
|
---|
313 | if ( !w || thread )
|
---|
314 | return;
|
---|
315 |
|
---|
316 | o = (Options *)opt;
|
---|
317 | IconsetSystemUI *d = (IconsetSystemUI *)w;
|
---|
318 | d->iss_system->clear();
|
---|
319 | QStringList loaded;
|
---|
320 |
|
---|
321 | d->setCursor(WaitCursor);
|
---|
322 |
|
---|
323 | QPalette customPal = d->palette();
|
---|
324 | customPal.setDisabled(customPal.inactive());
|
---|
325 | d->iss_system->setEnabled(false);
|
---|
326 | d->iss_system->setPalette(customPal);
|
---|
327 |
|
---|
328 | d->pb_sysDetails->setEnabled(false);
|
---|
329 | d->pb_sysDetails->setPalette(customPal);
|
---|
330 |
|
---|
331 | d->progress->show();
|
---|
332 | d->progress->setProgress( 0 );
|
---|
333 |
|
---|
334 | numIconsets = countIconsets("/system", loaded);
|
---|
335 | iconsetsLoaded = 0;
|
---|
336 |
|
---|
337 | cancelThread();
|
---|
338 |
|
---|
339 | thread = new IconsetLoadThread(this, "/system");
|
---|
340 | thread->start();
|
---|
341 | }
|
---|
342 |
|
---|
343 | bool OptionsTabIconsetSystem::event(QEvent *e)
|
---|
344 | {
|
---|
345 | IconsetSystemUI *d = (IconsetSystemUI *)w;
|
---|
346 | if ( e->type() == QEvent::User ) { // iconset load event
|
---|
347 | IconsetLoadEvent *le = (IconsetLoadEvent *)e;
|
---|
348 |
|
---|
349 | if ( thread != le->thread() )
|
---|
350 | return false;
|
---|
351 |
|
---|
352 | if ( !numIconsets )
|
---|
353 | numIconsets = 1;
|
---|
354 | d->progress->setProgress( (int)((float)100 * ++iconsetsLoaded / numIconsets) );
|
---|
355 |
|
---|
356 | Iconset *i = le->iconset();
|
---|
357 | if ( i ) {
|
---|
358 | is->stripFirstAnimFrame(i);
|
---|
359 | d->iss_system->insert(*i);
|
---|
360 |
|
---|
361 | QFileInfo fi( i->fileName() );
|
---|
362 | if ( fi.fileName() == o->systemIconset )
|
---|
363 | d->iss_system->setSelected(d->iss_system->count()-1, true);
|
---|
364 |
|
---|
365 | delete i;
|
---|
366 | }
|
---|
367 |
|
---|
368 | return true;
|
---|
369 | }
|
---|
370 | else if ( e->type() == QEvent::User + 1 ) { // finish event
|
---|
371 | d->iss_system->setEnabled(true);
|
---|
372 | d->iss_system->unsetPalette();
|
---|
373 |
|
---|
374 | d->pb_sysDetails->setEnabled(true);
|
---|
375 | d->pb_sysDetails->unsetPalette();
|
---|
376 |
|
---|
377 | connect(d->iss_system, SIGNAL(selectionChanged()), SIGNAL(dataChanged()));
|
---|
378 |
|
---|
379 | d->progress->hide();
|
---|
380 |
|
---|
381 | d->unsetCursor();
|
---|
382 | thread = 0;
|
---|
383 |
|
---|
384 | return true;
|
---|
385 | }
|
---|
386 |
|
---|
387 | return false;
|
---|
388 | }
|
---|
389 |
|
---|
390 | void OptionsTabIconsetSystem::previewIconset()
|
---|
391 | {
|
---|
392 | IconsetSystemUI *d = (IconsetSystemUI *)w;
|
---|
393 | const Iconset *is = d->iss_system->iconset();
|
---|
394 | if ( is )
|
---|
395 | isDetails(*is, parentWidget);
|
---|
396 | }
|
---|
397 |
|
---|
398 | void OptionsTabIconsetSystem::setData(PsiCon *, QWidget *p)
|
---|
399 | {
|
---|
400 | parentWidget = p;
|
---|
401 | }
|
---|
402 |
|
---|
403 | void OptionsTabIconsetSystem::cancelThread()
|
---|
404 | {
|
---|
405 | if ( thread ) {
|
---|
406 | threadCancelled.lock();
|
---|
407 | thread->cancelled = true;
|
---|
408 | threadCancelled.unlock();
|
---|
409 |
|
---|
410 | thread = 0;
|
---|
411 | }
|
---|
412 | }
|
---|
413 |
|
---|
414 | //----------------------------------------------------------------------------
|
---|
415 | // OptionsTabIconsetEmoticons
|
---|
416 | //----------------------------------------------------------------------------
|
---|
417 |
|
---|
418 | OptionsTabIconsetEmoticons::OptionsTabIconsetEmoticons(QObject *parent)
|
---|
419 | : OptionsTab(parent, "iconset_emoticons", "", tr("Emoticons"), tr("Select your emoticon iconsets"))
|
---|
420 | {
|
---|
421 | w = 0;
|
---|
422 | thread = 0;
|
---|
423 | }
|
---|
424 |
|
---|
425 | OptionsTabIconsetEmoticons::~OptionsTabIconsetEmoticons()
|
---|
426 | {
|
---|
427 | cancelThread();
|
---|
428 | }
|
---|
429 |
|
---|
430 | QWidget *OptionsTabIconsetEmoticons::widget()
|
---|
431 | {
|
---|
432 | if ( w )
|
---|
433 | return 0;
|
---|
434 |
|
---|
435 | w = new IconsetEmoUI;
|
---|
436 | IconsetEmoUI *d = (IconsetEmoUI *)w;
|
---|
437 |
|
---|
438 | connect(d->pb_emoUp, SIGNAL(clicked()), d->iss_emoticons, SLOT(moveItemUp()));
|
---|
439 | connect(d->pb_emoUp, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
---|
440 | connect(d->pb_emoDown, SIGNAL(clicked()), d->iss_emoticons, SLOT(moveItemDown()));
|
---|
441 | connect(d->pb_emoDown, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
---|
442 | connect(d->pb_emoDetails, SIGNAL(clicked()), SLOT(previewIconset()));
|
---|
443 |
|
---|
444 | QWhatsThis::add(d->ck_useEmoticons,
|
---|
445 | tr("<P>Emoticons are short sequences of characters that are used to convey an emotion or idea.</P>"
|
---|
446 | "<P>Enable this option if you want Psi to replace common emoticons with a graphical image.</P>"
|
---|
447 | "<P>For example, <B>:-)</B> would be replaced by <icon name=\"psi/smile\"></P>"));
|
---|
448 |
|
---|
449 | // TODO: add QWhatsThis
|
---|
450 |
|
---|
451 | return w;
|
---|
452 | }
|
---|
453 |
|
---|
454 | void OptionsTabIconsetEmoticons::applyOptions(Options *opt)
|
---|
455 | {
|
---|
456 | if ( !w || thread )
|
---|
457 | return;
|
---|
458 |
|
---|
459 | IconsetEmoUI *d = (IconsetEmoUI *)w;
|
---|
460 | opt->useEmoticons = d->ck_useEmoticons->isChecked();
|
---|
461 |
|
---|
462 | opt->emoticons.clear();
|
---|
463 | IconWidgetItem *item = (IconWidgetItem *)d->iss_emoticons->firstItem();
|
---|
464 | while ( item ) {
|
---|
465 | if ( item->isSelected() ) {
|
---|
466 | const Iconset *is = item->iconset();
|
---|
467 | if ( is ) {
|
---|
468 | QFileInfo fi( is->fileName() );
|
---|
469 | opt->emoticons << fi.fileName();
|
---|
470 | }
|
---|
471 | }
|
---|
472 |
|
---|
473 | item = (IconWidgetItem *)item->next();
|
---|
474 | }
|
---|
475 |
|
---|
476 | }
|
---|
477 |
|
---|
478 | void OptionsTabIconsetEmoticons::restoreOptions(const Options *opt)
|
---|
479 | {
|
---|
480 | if ( !w || thread )
|
---|
481 | return;
|
---|
482 |
|
---|
483 | IconsetEmoUI *d = (IconsetEmoUI *)w;
|
---|
484 | d->ck_useEmoticons->setChecked( opt->useEmoticons );
|
---|
485 |
|
---|
486 | // fill in the iconset view
|
---|
487 | d->iss_emoticons->clear();
|
---|
488 |
|
---|
489 | {
|
---|
490 | QPtrListIterator<Iconset> it ( is->emoticons );
|
---|
491 | Iconset *is;
|
---|
492 | for ( ; (is = it.current()); ++it) {
|
---|
493 | d->iss_emoticons->insert(*is);
|
---|
494 | d->iss_emoticons->setSelected(d->iss_emoticons->count()-1, true);
|
---|
495 | }
|
---|
496 | }
|
---|
497 |
|
---|
498 |
|
---|
499 | {
|
---|
500 | QStringList loaded;
|
---|
501 | {
|
---|
502 | QPtrListIterator<Iconset> it( is->emoticons );
|
---|
503 | Iconset *tmp;
|
---|
504 | for ( ; (tmp = it.current()); ++it) {
|
---|
505 | QFileInfo fi ( tmp->fileName() );
|
---|
506 | loaded << fi.fileName();
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | d->setCursor(WaitCursor);
|
---|
511 |
|
---|
512 | QPalette customPal = d->palette();
|
---|
513 | customPal.setDisabled(customPal.inactive());
|
---|
514 | d->ck_useEmoticons->setEnabled(false);
|
---|
515 | d->ck_useEmoticons->setPalette(customPal);
|
---|
516 |
|
---|
517 | d->groupBox9->setEnabled(false);
|
---|
518 | d->groupBox9->setPalette(customPal);
|
---|
519 |
|
---|
520 | d->progress->show();
|
---|
521 | d->progress->setProgress( 0 );
|
---|
522 |
|
---|
523 | numIconsets = countIconsets("/emoticons", loaded);
|
---|
524 | iconsetsLoaded = 0;
|
---|
525 |
|
---|
526 | cancelThread();
|
---|
527 |
|
---|
528 | thread = new IconsetLoadThread(this, "/emoticons");
|
---|
529 | thread->excludeIconsets(loaded);
|
---|
530 | thread->start();
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | bool OptionsTabIconsetEmoticons::event(QEvent *e)
|
---|
535 | {
|
---|
536 | IconsetEmoUI *d = (IconsetEmoUI *)w;
|
---|
537 | if ( e->type() == QEvent::User ) { // iconset load event
|
---|
538 | IconsetLoadEvent *le = (IconsetLoadEvent *)e;
|
---|
539 |
|
---|
540 | if ( thread != le->thread() )
|
---|
541 | return false;
|
---|
542 |
|
---|
543 | if ( !numIconsets )
|
---|
544 | numIconsets = 1;
|
---|
545 | d->progress->setProgress( (int)((float)100 * ++iconsetsLoaded / numIconsets) );
|
---|
546 |
|
---|
547 | Iconset *is = le->iconset();
|
---|
548 | if ( is ) {
|
---|
549 | PsiIconset::removeAnimation(is);
|
---|
550 | d->iss_emoticons->insert(*is);
|
---|
551 | delete is;
|
---|
552 | }
|
---|
553 |
|
---|
554 | return true;
|
---|
555 | }
|
---|
556 | else if ( e->type() == QEvent::User + 1 ) { // finish event
|
---|
557 | d->ck_useEmoticons->setEnabled(true);
|
---|
558 | d->ck_useEmoticons->unsetPalette();
|
---|
559 |
|
---|
560 | d->groupBox9->setEnabled(true);
|
---|
561 | d->groupBox9->unsetPalette();
|
---|
562 |
|
---|
563 | connect(d->iss_emoticons, SIGNAL(selectionChanged()), SIGNAL(dataChanged()));
|
---|
564 |
|
---|
565 | bool checked = d->ck_useEmoticons->isChecked();
|
---|
566 | d->ck_useEmoticons->setChecked( true );
|
---|
567 | d->ck_useEmoticons->setChecked( checked );
|
---|
568 |
|
---|
569 | d->progress->hide();
|
---|
570 |
|
---|
571 | d->unsetCursor();
|
---|
572 | thread = 0;
|
---|
573 |
|
---|
574 | return true;
|
---|
575 | }
|
---|
576 |
|
---|
577 | return false;
|
---|
578 | }
|
---|
579 |
|
---|
580 | void OptionsTabIconsetEmoticons::previewIconset()
|
---|
581 | {
|
---|
582 | IconsetEmoUI *d = (IconsetEmoUI *)w;
|
---|
583 | const Iconset *is = d->iss_emoticons->iconset();
|
---|
584 | if ( is )
|
---|
585 | isDetails(*is, parentWidget);
|
---|
586 | }
|
---|
587 |
|
---|
588 | void OptionsTabIconsetEmoticons::setData(PsiCon *, QWidget *p)
|
---|
589 | {
|
---|
590 | parentWidget = p;
|
---|
591 | }
|
---|
592 |
|
---|
593 | void OptionsTabIconsetEmoticons::cancelThread()
|
---|
594 | {
|
---|
595 | if ( thread ) {
|
---|
596 | threadCancelled.lock();
|
---|
597 | thread->cancelled = true;
|
---|
598 | threadCancelled.unlock();
|
---|
599 |
|
---|
600 | thread = 0;
|
---|
601 | }
|
---|
602 | }
|
---|
603 |
|
---|
604 | //----------------------------------------------------------------------------
|
---|
605 | // OptionsTabIconsetRoster
|
---|
606 | //----------------------------------------------------------------------------
|
---|
607 |
|
---|
608 | OptionsTabIconsetRoster::OptionsTabIconsetRoster(QObject *parent)
|
---|
609 | : OptionsTab(parent, "iconset_roster", "", tr("Roster Icons"), tr("Select iconsets for your roster"))
|
---|
610 | {
|
---|
611 | w = 0;
|
---|
612 | thread = 0;
|
---|
613 | }
|
---|
614 |
|
---|
615 | OptionsTabIconsetRoster::~OptionsTabIconsetRoster()
|
---|
616 | {
|
---|
617 | cancelThread();
|
---|
618 | }
|
---|
619 |
|
---|
620 | QWidget *OptionsTabIconsetRoster::widget()
|
---|
621 | {
|
---|
622 | if ( w )
|
---|
623 | return 0;
|
---|
624 |
|
---|
625 | w = new IconsetRosterUI;
|
---|
626 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
627 |
|
---|
628 | connect(d->pb_defRosterDetails, SIGNAL(clicked()), SLOT(defaultDetails()));
|
---|
629 |
|
---|
630 | connect(d->iss_servicesRoster, SIGNAL(selectionChanged(QListBoxItem *)), SLOT(isServices_iconsetSelected(QListBoxItem *)));
|
---|
631 | connect(d->lv_isServices, SIGNAL(selectionChanged(QListViewItem *)), SLOT(isServices_selectionChanged(QListViewItem *)));
|
---|
632 | connect(d->pb_servicesDetails, SIGNAL(clicked()), SLOT(servicesDetails()));
|
---|
633 | isServices_selectionChanged(0);
|
---|
634 |
|
---|
635 | connect(d->iss_customRoster, SIGNAL(selectionChanged(QListBoxItem *)), SLOT(isCustom_iconsetSelected(QListBoxItem *)));
|
---|
636 | connect(d->lv_customRoster, SIGNAL(selectionChanged(QListViewItem *)), SLOT(isCustom_selectionChanged(QListViewItem *)));
|
---|
637 | connect(d->pb_customRosterDetails, SIGNAL(clicked()), SLOT(customDetails()));
|
---|
638 | connect(d->le_customRoster, SIGNAL(textChanged(const QString &)), SLOT(isCustom_textChanged()));
|
---|
639 | connect(d->pb_customRosterAdd, SIGNAL(clicked()), SLOT(isCustom_add()));
|
---|
640 | connect(d->pb_customRosterDelete, SIGNAL(clicked()), SLOT(isCustom_delete()));
|
---|
641 | isCustom_selectionChanged(0);
|
---|
642 |
|
---|
643 | QWhatsThis::add(d->ck_useTransportIconsForContacts,
|
---|
644 | tr("Toggles use of transport icons to the contacts, that use that transports."));
|
---|
645 |
|
---|
646 | // TODO: add QWhatsThis
|
---|
647 |
|
---|
648 | return w;
|
---|
649 | }
|
---|
650 |
|
---|
651 | void OptionsTabIconsetRoster::applyOptions(Options *opt)
|
---|
652 | {
|
---|
653 | if ( !w || thread )
|
---|
654 | return;
|
---|
655 |
|
---|
656 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
657 | opt->useTransportIconsForContacts = d->ck_useTransportIconsForContacts->isChecked();
|
---|
658 |
|
---|
659 | // roster - default
|
---|
660 | {
|
---|
661 | const Iconset *is = d->iss_defRoster->iconset();
|
---|
662 | if ( is ) {
|
---|
663 | QFileInfo fi( is->fileName() );
|
---|
664 | opt->defaultRosterIconset = fi.fileName();
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | // roster - services
|
---|
669 | {
|
---|
670 | opt->serviceRosterIconset.clear();
|
---|
671 |
|
---|
672 | QListViewItemIterator it( d->lv_isServices );
|
---|
673 | for ( ; it.current(); ++it) {
|
---|
674 | QListViewItem *item = it.current();
|
---|
675 |
|
---|
676 | opt->serviceRosterIconset[item->text(2)] = item->text(3);
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | // roster - custom
|
---|
681 | {
|
---|
682 | opt->customRosterIconset.clear();
|
---|
683 |
|
---|
684 | QListViewItemIterator it( d->lv_customRoster );
|
---|
685 | for ( ; it.current(); ++it) {
|
---|
686 | QListViewItem *item = it.current();
|
---|
687 |
|
---|
688 | opt->customRosterIconset[item->text(2)] = item->text(3);
|
---|
689 | }
|
---|
690 | }
|
---|
691 | }
|
---|
692 |
|
---|
693 | void OptionsTabIconsetRoster::restoreOptions(const Options *opt)
|
---|
694 | {
|
---|
695 | if ( !w || thread )
|
---|
696 | return;
|
---|
697 |
|
---|
698 | o = (Options *)opt;
|
---|
699 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
700 | d->ck_useTransportIconsForContacts->setChecked( opt->useTransportIconsForContacts );
|
---|
701 |
|
---|
702 | d->iss_defRoster->clear();
|
---|
703 | d->iss_servicesRoster->clear();
|
---|
704 | d->iss_customRoster->clear();
|
---|
705 |
|
---|
706 | QStringList loaded;
|
---|
707 |
|
---|
708 | d->setCursor(WaitCursor);
|
---|
709 |
|
---|
710 | QPalette customPal = d->palette();
|
---|
711 | customPal.setDisabled(customPal.inactive());
|
---|
712 | d->tabWidget3->setEnabled(false);
|
---|
713 | d->tabWidget3->setPalette(customPal);
|
---|
714 |
|
---|
715 | d->progress->show();
|
---|
716 | d->progress->setProgress( 0 );
|
---|
717 |
|
---|
718 | numIconsets = countIconsets("/roster", loaded);
|
---|
719 | iconsetsLoaded = 0;
|
---|
720 |
|
---|
721 | cancelThread();
|
---|
722 |
|
---|
723 | thread = new IconsetLoadThread(this, "/roster");
|
---|
724 | thread->start();
|
---|
725 | }
|
---|
726 |
|
---|
727 | bool OptionsTabIconsetRoster::event(QEvent *e)
|
---|
728 | {
|
---|
729 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
730 | if ( e->type() == QEvent::User ) { // iconset load event
|
---|
731 | IconsetLoadEvent *le = (IconsetLoadEvent *)e;
|
---|
732 |
|
---|
733 | if ( thread != le->thread() )
|
---|
734 | return false;
|
---|
735 |
|
---|
736 | if ( !numIconsets )
|
---|
737 | numIconsets = 1;
|
---|
738 | d->progress->setProgress( (int)((float)100 * ++iconsetsLoaded / numIconsets) );
|
---|
739 |
|
---|
740 | Iconset *i = le->iconset();
|
---|
741 | if ( i ) {
|
---|
742 | is->stripFirstAnimFrame(i);
|
---|
743 | QFileInfo fi( i->fileName() );
|
---|
744 |
|
---|
745 | // roster - default
|
---|
746 | d->iss_defRoster->insert(*i);
|
---|
747 | if ( fi.fileName() == o->defaultRosterIconset )
|
---|
748 | d->iss_defRoster->setSelected(d->iss_defRoster->count()-1, true);
|
---|
749 |
|
---|
750 | // roster - service
|
---|
751 | d->iss_servicesRoster->insert(*i);
|
---|
752 |
|
---|
753 | // roster - custom
|
---|
754 | d->iss_customRoster->insert(*i);
|
---|
755 |
|
---|
756 | delete i;
|
---|
757 | }
|
---|
758 |
|
---|
759 | return true;
|
---|
760 | }
|
---|
761 | else if ( e->type() == QEvent::User + 1 ) { // finish event
|
---|
762 | // roster - service
|
---|
763 | {
|
---|
764 | // fill the QListView
|
---|
765 | QListViewItemIterator it( d->lv_isServices );
|
---|
766 | for ( ; it.current(); ++it) {
|
---|
767 | QListViewItem *i = it.current();
|
---|
768 | if ( !i->text(2).isEmpty() ) {
|
---|
769 | Iconset *iss = is->roster[o->serviceRosterIconset[i->text(2)]];
|
---|
770 | if ( iss ) {
|
---|
771 | i->setText(1, iss->name());
|
---|
772 |
|
---|
773 | QFileInfo fi ( iss->fileName() );
|
---|
774 | i->setText(3, fi.fileName());
|
---|
775 | }
|
---|
776 | }
|
---|
777 | }
|
---|
778 |
|
---|
779 | QHeader *head = d->lv_isServices->header();
|
---|
780 | head->removeLabel(2);
|
---|
781 | }
|
---|
782 |
|
---|
783 | // roster - custom
|
---|
784 | {
|
---|
785 | // Then, fill the QListView
|
---|
786 | QListViewItem *last = 0;
|
---|
787 | QMap<QString, QString>::ConstIterator it = o->customRosterIconset.begin();
|
---|
788 | for ( ; it != o->customRosterIconset.end(); ++it) {
|
---|
789 | QListViewItem *item = new QListViewItem(d->lv_customRoster, last);
|
---|
790 | last = item;
|
---|
791 |
|
---|
792 | item->setText(0, clipCustomText(it.key())); // RegExp
|
---|
793 | item->setText(2, it.key());
|
---|
794 |
|
---|
795 | Iconset *iss = is->roster[it.data()];
|
---|
796 | if ( iss ) {
|
---|
797 | item->setText(1, iss->name());
|
---|
798 |
|
---|
799 | QFileInfo fi ( iss->fileName() );
|
---|
800 | item->setText(3, fi.fileName());
|
---|
801 | }
|
---|
802 | }
|
---|
803 | }
|
---|
804 |
|
---|
805 | d->tabWidget3->setEnabled(true);
|
---|
806 | d->tabWidget3->unsetPalette();
|
---|
807 |
|
---|
808 | connect(d->iss_defRoster, SIGNAL(selectionChanged()), SIGNAL(dataChanged()));
|
---|
809 | connect(d->iss_servicesRoster, SIGNAL(selectionChanged()), SIGNAL(dataChanged()));
|
---|
810 | connect(d->iss_customRoster, SIGNAL(selectionChanged()), SIGNAL(dataChanged()));
|
---|
811 |
|
---|
812 | d->progress->hide();
|
---|
813 |
|
---|
814 | d->unsetCursor();
|
---|
815 | thread = 0;
|
---|
816 |
|
---|
817 | return true;
|
---|
818 | }
|
---|
819 |
|
---|
820 | return false;
|
---|
821 | }
|
---|
822 |
|
---|
823 | void OptionsTabIconsetRoster::setData(PsiCon *, QWidget *p)
|
---|
824 | {
|
---|
825 | parentWidget = p;
|
---|
826 | }
|
---|
827 |
|
---|
828 | void OptionsTabIconsetRoster::defaultDetails()
|
---|
829 | {
|
---|
830 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
831 | const Iconset *is = d->iss_defRoster->iconset();
|
---|
832 | if ( is )
|
---|
833 | isDetails(*is, parentWidget);
|
---|
834 | }
|
---|
835 |
|
---|
836 | void OptionsTabIconsetRoster::servicesDetails()
|
---|
837 | {
|
---|
838 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
839 | const Iconset *is = d->iss_servicesRoster->iconset();
|
---|
840 | if ( is )
|
---|
841 | isDetails(*is, parentWidget);
|
---|
842 | }
|
---|
843 |
|
---|
844 | void OptionsTabIconsetRoster::customDetails()
|
---|
845 | {
|
---|
846 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
847 | const Iconset *is = d->iss_customRoster->iconset();
|
---|
848 | if ( is )
|
---|
849 | isDetails(*is, parentWidget);
|
---|
850 | }
|
---|
851 |
|
---|
852 | //------------------------------------------------------------
|
---|
853 |
|
---|
854 | void OptionsTabIconsetRoster::isServices_iconsetSelected(QListBoxItem *item)
|
---|
855 | {
|
---|
856 | if ( !item )
|
---|
857 | return;
|
---|
858 |
|
---|
859 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
860 | QListViewItem *it = d->lv_isServices->selectedItem();
|
---|
861 | if ( !it )
|
---|
862 | return;
|
---|
863 |
|
---|
864 | const Iconset *is = ((IconWidgetItem *)item)->iconset();
|
---|
865 | if ( !is )
|
---|
866 | return;
|
---|
867 |
|
---|
868 | it->setText(1, is->name());
|
---|
869 | QFileInfo fi ( is->fileName() );
|
---|
870 | it->setText(3, fi.fileName());
|
---|
871 | }
|
---|
872 |
|
---|
873 | void OptionsTabIconsetRoster::isServices_selectionChanged(QListViewItem *it)
|
---|
874 | {
|
---|
875 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
876 | d->iss_servicesRoster->setEnabled( it != 0 );
|
---|
877 | d->pb_servicesDetails->setEnabled( it != 0 );
|
---|
878 | d->iss_servicesRoster->clearSelection();
|
---|
879 | if ( !it )
|
---|
880 | return;
|
---|
881 |
|
---|
882 | if ( it->text(3).isEmpty() )
|
---|
883 | return;
|
---|
884 |
|
---|
885 | QString name = it->text(3);
|
---|
886 |
|
---|
887 | emit noDirty(true);
|
---|
888 | IconWidgetItem *item = (IconWidgetItem *)d->iss_servicesRoster->firstItem();
|
---|
889 | for ( ; item; item = (IconWidgetItem *)item->next()) {
|
---|
890 | const Iconset *is = item->iconset();
|
---|
891 | if ( is ) {
|
---|
892 | QFileInfo fi ( is->fileName() );
|
---|
893 | if ( fi.fileName() == name ) {
|
---|
894 | emit noDirty(true);
|
---|
895 | d->iss_servicesRoster->setSelected(item, true);
|
---|
896 | d->iss_servicesRoster->ensureCurrentVisible();
|
---|
897 | emit noDirty(false);
|
---|
898 | break;
|
---|
899 | }
|
---|
900 | }
|
---|
901 | }
|
---|
902 | qApp->processEvents();
|
---|
903 | emit noDirty(false);
|
---|
904 | }
|
---|
905 |
|
---|
906 | //------------------------------------------------------------
|
---|
907 |
|
---|
908 | void OptionsTabIconsetRoster::isCustom_iconsetSelected(QListBoxItem *item)
|
---|
909 | {
|
---|
910 | if ( !item )
|
---|
911 | return;
|
---|
912 |
|
---|
913 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
914 | QListViewItem *it = d->lv_customRoster->selectedItem();
|
---|
915 | if ( !it )
|
---|
916 | return;
|
---|
917 |
|
---|
918 | const Iconset *is = ((IconWidgetItem *)item)->iconset();
|
---|
919 | if ( !is )
|
---|
920 | return;
|
---|
921 |
|
---|
922 | it->setText(1, is->name());
|
---|
923 | QFileInfo fi ( is->fileName() );
|
---|
924 | it->setText(3, fi.fileName());
|
---|
925 | }
|
---|
926 |
|
---|
927 | void OptionsTabIconsetRoster::isCustom_selectionChanged(QListViewItem *it)
|
---|
928 | {
|
---|
929 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
930 | d->iss_customRoster->setEnabled( it != 0 );
|
---|
931 | d->pb_customRosterDetails->setEnabled( it != 0 );
|
---|
932 | //d->pb_customRosterAdd->setEnabled( it != 0 );
|
---|
933 | d->pb_customRosterDelete->setEnabled( it != 0 );
|
---|
934 | d->le_customRoster->setEnabled( it != 0 );
|
---|
935 | d->iss_customRoster->clearSelection();
|
---|
936 | if ( !it )
|
---|
937 | return;
|
---|
938 |
|
---|
939 | if ( it->text(3).isEmpty() )
|
---|
940 | return;
|
---|
941 |
|
---|
942 | emit noDirty(true);
|
---|
943 | d->le_customRoster->setText(it->text(2));
|
---|
944 | QString name = it->text(3);
|
---|
945 |
|
---|
946 | IconWidgetItem *item = (IconWidgetItem *)d->iss_customRoster->firstItem();
|
---|
947 | for ( ; item; item = (IconWidgetItem *)item->next()) {
|
---|
948 | const Iconset *is = item->iconset();
|
---|
949 | if ( is ) {
|
---|
950 | QFileInfo fi ( is->fileName() );
|
---|
951 | if ( fi.fileName() == name ) {
|
---|
952 | d->iss_customRoster->setSelected(item, true);
|
---|
953 | d->iss_customRoster->ensureCurrentVisible();
|
---|
954 | break;
|
---|
955 | }
|
---|
956 | }
|
---|
957 | }
|
---|
958 | qApp->processEvents();
|
---|
959 | emit noDirty(false);
|
---|
960 | }
|
---|
961 |
|
---|
962 | void OptionsTabIconsetRoster::isCustom_textChanged()
|
---|
963 | {
|
---|
964 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
965 | QListViewItem *item = d->lv_customRoster->selectedItem();
|
---|
966 | if ( !item )
|
---|
967 | return;
|
---|
968 |
|
---|
969 | item->setText( 0, clipCustomText(d->le_customRoster->text()) );
|
---|
970 | item->setText( 2, d->le_customRoster->text() );
|
---|
971 | }
|
---|
972 |
|
---|
973 | void OptionsTabIconsetRoster::isCustom_add()
|
---|
974 | {
|
---|
975 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
976 |
|
---|
977 | QString def;
|
---|
978 | const Iconset *iconset = d->iss_defRoster->iconset();
|
---|
979 | if ( is ) {
|
---|
980 | QFileInfo fi( iconset->fileName() );
|
---|
981 | def = fi.fileName();
|
---|
982 | }
|
---|
983 | else
|
---|
984 | qWarning("OptionsTabIconsetRoster::isCustom_add(): 'def' is null!");
|
---|
985 |
|
---|
986 | QListViewItem *item = new QListViewItem(d->lv_customRoster, d->lv_customRoster->lastItem());
|
---|
987 | const Iconset *i = is->roster[def];
|
---|
988 | if ( i ) {
|
---|
989 | item->setText(1, i->name());
|
---|
990 |
|
---|
991 | QFileInfo fi(i->fileName());
|
---|
992 | item->setText(3, fi.fileName());
|
---|
993 | }
|
---|
994 |
|
---|
995 | d->lv_customRoster->setSelected(item, true);
|
---|
996 | emit dataChanged();
|
---|
997 |
|
---|
998 | d->le_customRoster->setFocus();
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | void OptionsTabIconsetRoster::isCustom_delete()
|
---|
1002 | {
|
---|
1003 | IconsetRosterUI *d = (IconsetRosterUI *)w;
|
---|
1004 | QListViewItem *item = d->lv_customRoster->selectedItem();
|
---|
1005 | if ( !item )
|
---|
1006 | return;
|
---|
1007 |
|
---|
1008 | delete item;
|
---|
1009 | isCustom_selectionChanged(0);
|
---|
1010 | emit dataChanged();
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | QString OptionsTabIconsetRoster::clipCustomText(QString s)
|
---|
1014 | {
|
---|
1015 | if ( s.length() > 10 ) {
|
---|
1016 | s = s.left(9);
|
---|
1017 | s += "...";
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | return s;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | void OptionsTabIconsetRoster::cancelThread()
|
---|
1024 | {
|
---|
1025 | if ( thread ) {
|
---|
1026 | threadCancelled.lock();
|
---|
1027 | thread->cancelled = true;
|
---|
1028 | threadCancelled.unlock();
|
---|
1029 |
|
---|
1030 | thread = 0;
|
---|
1031 | }
|
---|
1032 | }
|
---|