~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to src/common.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "psievent.h"
25
25
#include "psiiconset.h"
26
26
#include "applicationinfo.h"
 
27
#include "psioptions.h"
27
28
 
28
29
#include <QUrl>
29
30
#include <QProcess>
34
35
#include <QSound>
35
36
#include <QObject>
36
37
#include <QMessageBox>
 
38
#include <QUuid>
 
39
#include <QDir>
37
40
 
38
41
#include <stdio.h>
39
42
#ifdef Q_WS_X11
56
59
 
57
60
Qt::WFlags psi_dialog_flags = (Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
58
61
 
59
 
Options option;
 
62
// used to be part of the global options struct. 
 
63
// FIXME find it a new home!
 
64
int common_smallFontSize=0;
 
65
 
 
66
 
60
67
bool useSound;
61
68
 
62
69
 
225
232
}
226
233
 
227
234
 
228
 
void soundPlay(const QString &str)
229
 
{
 
235
/** Detect default player helper on unix like systems
 
236
 */
 
237
QString soundDetectPlayer()
 
238
{
 
239
        // prefer ALSA on linux
 
240
        if (QFile("/proc/asound").exists()) {
 
241
                return "aplay";
 
242
        }
 
243
        // fallback to "play"
 
244
        return "play";
 
245
        
 
246
}
 
247
 
 
248
void soundPlay(const QString &s)
 
249
{
 
250
        QString str = s;
230
251
        if(str == "!beep") {
231
252
                QApplication::beep();
232
253
                return;
233
254
        }
 
255
        
 
256
        if (QDir::isRelativePath(str)) {
 
257
                str = ApplicationInfo::resourcesDir() + "/" + str;
 
258
        }
234
259
 
235
260
        if(!QFile::exists(str))
236
261
                return;
238
263
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
239
264
        QSound::play(str);
240
265
#else
241
 
        if(!option.player.isEmpty()) {
242
 
                QStringList args;
243
 
                args = QStringList::split(' ', option.player);
244
 
                args += str;
245
 
                QString prog = args.takeFirst();
246
 
                QProcess::startDetached(prog, args);
247
 
        }
 
266
        QString player = PsiOptions::instance()->getOption("options.ui.notifications.sounds.unix-sound-player").toString();
 
267
        if (player == "") player = soundDetectPlayer();
 
268
        QStringList args;
 
269
        args = QStringList::split(' ', player);
 
270
        args += str;
 
271
        QString prog = args.takeFirst();
 
272
        QProcess::startDetached(prog, args);
248
273
#endif
249
274
}
250
275
 
421
446
        long dsk, curr_dsk;
422
447
        Window win = w->winId();
423
448
        if(desktopOfWindow(&win, &dsk) && currentDesktop(&curr_dsk)) {
424
 
                if((dsk != curr_dsk) && (dsk != 0xFFFFFFFF)) {  // second condition for sticky windows
 
449
                //qDebug() << "bringToFront current desktop=" << curr_dsk << " windowDesktop=" << dsk;
 
450
                if((dsk != curr_dsk) && (dsk != -1)) {  // second condition for sticky windows
425
451
                        w->hide();
426
452
                }
427
453
        }
457
483
        return false;
458
484
}
459
485
 
 
486
//----------------------------------------------------------------------------
 
487
// ToolbarPrefs
 
488
//----------------------------------------------------------------------------
 
489
 
 
490
ToolbarPrefs::ToolbarPrefs()
 
491
        : dock(Qt::DockTop)
 
492
        // , dirty(true)
 
493
        , on(false)
 
494
        , locked(false)
 
495
        // , stretchable(false)
 
496
        // , index(0)
 
497
        , nl(true)
 
498
        // , extraOffset(0)
 
499
{
 
500
        id = QUuid::createUuid().toString();
 
501
}
 
502
 
 
503
bool ToolbarPrefs::operator==(const ToolbarPrefs& other)
 
504
{
 
505
        return id == other.id &&
 
506
               name == other.name &&
 
507
               keys == other.keys &&
 
508
               dock == other.dock &&
 
509
               // dirty == other.dirty &&
 
510
               on == other.on &&
 
511
               locked == other.locked &&
 
512
               // stretchable == other.stretchable &&
 
513
               // index == other.index &&
 
514
               nl == other.nl;
 
515
               // extraOffset == other.extraOffset;
 
516
}
 
517
 
 
518
 
 
519
int versionStringToInt(const char* version)
 
520
{
 
521
        QString str = QString::fromLatin1(version);
 
522
        QStringList parts = str.split('.', QString::KeepEmptyParts);
 
523
        if (parts.count() != 3) {
 
524
                return 0;
 
525
        }
 
526
 
 
527
        int versionInt = 0;
 
528
        for (int n = 0; n < 3; ++n) {
 
529
                bool ok;
 
530
                int x = parts[n].toInt(&ok);
 
531
                if (ok && x >= 0 && x <= 0xff) {
 
532
                        versionInt <<= 8;
 
533
                        versionInt += x;
 
534
                } else {
 
535
                        return 0;
 
536
                }
 
537
        }
 
538
        return versionInt;
 
539
}
 
540
 
 
541
int qVersionInt()
 
542
{
 
543
        static int out = -1;
 
544
        if (out == -1) {
 
545
                out = versionStringToInt(qVersion());
 
546
        }
 
547
        return out;
 
548
}