~unity-2d-team/unity-2d/natty

« back to all changes in this revision

Viewing changes to launcher/UnityApplications/launcherapplication.cpp

  • Committer: Tarmac
  • Author(s): Florian Boucault
  • Date: 2011-03-23 17:31:31 UTC
  • mfrom: (476.2.8 startup_notification)
  • Revision ID: ubuntu.builder@gmail.com-20110323173131-zecdrbzmdb60c6la
[launcher] Added support for startup notification protocol.

Launcher now depends on libstartup-notification.
  
New APIs:
- LauncherApplication::executable QString property
- LauncherApplication::setSnStartupSequence(SnStartupSequence* sequence)
  
LauncherApplication::launching is updated depending on the startup notification sequence set to the LauncherApplication.
LauncherApplications created for startup notification are matched with their corresponding BamfApplication based on their executable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <QFile>
46
46
#include <QFileSystemWatcher>
47
47
 
 
48
extern "C" {
 
49
#include <libsn/sn.h>
 
50
}
 
51
 
48
52
LauncherApplication::LauncherApplication()
49
53
    : m_application(NULL)
50
54
    , m_desktopFileWatcher(NULL)
51
55
    , m_appInfo(NULL)
 
56
    , m_snStartupSequence(NULL)
52
57
    , m_sticky(false)
53
58
    , m_has_visible_window(false)
54
59
    , m_progress(0), m_progressBarVisible(false)
72
77
        client_type_set = true;
73
78
    }
74
79
 
 
80
    m_launching_timer.setSingleShot(true);
 
81
    m_launching_timer.setInterval(8000);
75
82
    QObject::connect(&m_launching_timer, SIGNAL(timeout()), this, SLOT(onLaunchingTimeouted()));
76
83
}
77
84
 
87
94
 
88
95
LauncherApplication::~LauncherApplication()
89
96
{
 
97
    if (m_snStartupSequence != NULL) {
 
98
        sn_startup_sequence_unref(m_snStartupSequence);
 
99
        m_snStartupSequence = NULL;
 
100
    }
 
101
 
90
102
    if (m_application != NULL) {
 
103
        m_application->disconnect(this);
91
104
        m_application = NULL;
92
105
    }
93
106
 
178
191
        return QString::fromUtf8(g_app_info_get_name((GAppInfo*)m_appInfo));
179
192
    }
180
193
 
 
194
    if (m_snStartupSequence != NULL) {
 
195
        return QString::fromUtf8(sn_startup_sequence_get_name(m_snStartupSequence));
 
196
    }
 
197
 
181
198
    return QString("");
182
199
}
183
200
 
192
209
        return QString::fromUtf8(g_icon_to_string(g_app_info_get_icon((GAppInfo*)m_appInfo)));
193
210
    }
194
211
 
 
212
    if (m_snStartupSequence != NULL) {
 
213
        return QString::fromUtf8(sn_startup_sequence_get_icon_name(m_snStartupSequence));
 
214
    }
 
215
 
195
216
    return QString("");
196
217
}
197
218
 
219
240
    return QString("");
220
241
}
221
242
 
 
243
QString
 
244
LauncherApplication::executable() const
 
245
{
 
246
    if (m_appInfo != NULL) {
 
247
        return QString::fromUtf8(g_app_info_get_executable((GAppInfo*)m_appInfo));
 
248
    }
 
249
 
 
250
    if (m_snStartupSequence != NULL) {
 
251
        return QString::fromUtf8(sn_startup_sequence_get_binary_name(m_snStartupSequence));
 
252
    }
 
253
 
 
254
    return QString("");
 
255
}
 
256
 
222
257
void
223
258
LauncherApplication::setSticky(bool sticky)
224
259
{
248
283
    /* Emit the Changed signal on all properties that can depend on m_appInfo
249
284
       m_application's properties take precedence over m_appInfo's
250
285
    */
251
 
    if (m_application == NULL && m_appInfo != NULL) {
252
 
        emit desktopFileChanged(desktop_file);
253
 
        emit nameChanged(name());
254
 
        emit iconChanged(icon());
 
286
    if (m_appInfo != NULL) {
 
287
        if (m_application == NULL) {
 
288
            Q_EMIT desktopFileChanged(desktop_file);
 
289
            Q_EMIT nameChanged(name());
 
290
            Q_EMIT iconChanged(icon());
 
291
        }
 
292
        Q_EMIT executableChanged(executable());
255
293
    }
256
294
 
257
295
    monitorDesktopFile(this->desktop_file());
262
300
{
263
301
    /* Monitor the desktop file for live changes */
264
302
    if (m_desktopFileWatcher == NULL) {
 
303
        /* FIXME: deleting a QFileSystemWatcher can be quite slow (sometimes
 
304
           around 100ms on a powerful computer) and can provoke visual glitches
 
305
           where the user interface is blocked for a short moment.
 
306
         */
265
307
        m_desktopFileWatcher = new QFileSystemWatcher(this);
266
308
        connect(m_desktopFileWatcher, SIGNAL(fileChanged(const QString&)),
267
309
                SLOT(onDesktopFileChanged(const QString&)));
385
427
}
386
428
 
387
429
void
 
430
LauncherApplication::setSnStartupSequence(SnStartupSequence* sequence)
 
431
{
 
432
    if (sequence != NULL) {
 
433
        if (!sn_startup_sequence_get_completed(sequence)) {
 
434
            /* 'launching' property becomes true for a few seconds */
 
435
            m_launching_timer.start();
 
436
        } else {
 
437
            m_launching_timer.stop();
 
438
        }
 
439
        sn_startup_sequence_ref(sequence);
 
440
    }
 
441
 
 
442
    if (m_snStartupSequence != NULL) {
 
443
        sn_startup_sequence_unref(m_snStartupSequence);
 
444
    }
 
445
 
 
446
    m_snStartupSequence = sequence;
 
447
 
 
448
    emit nameChanged(name());
 
449
    emit iconChanged(icon());
 
450
    emit executableChanged(executable());
 
451
    emit launchingChanged(launching());
 
452
}
 
453
 
 
454
void
388
455
LauncherApplication::setIconGeometry(int x, int y, int width, int height, uint xid)
389
456
{
390
457
    if (m_application == NULL) {
565
632
        return false;
566
633
    }
567
634
 
568
 
    /* 'launching' property becomes true for a maximum of 8 seconds and becomes
 
635
    /* 'launching' property becomes true for a few seconds and becomes
569
636
       false as soon as the application is launched */
570
 
    m_launching_timer.setSingleShot(true);
571
 
    m_launching_timer.start(8000);
 
637
    m_launching_timer.start();
572
638
    emit launchingChanged(true);
573
639
 
574
640
    return true;