~ubuntu-branches/ubuntu/precise/kactivities/precise-proposed

« back to all changes in this revision

Viewing changes to service/ActivityManager.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-03-30 20:00:33 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120330200033-m454p8g54y2idwla
Tags: 4:4.8.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
      windows(_windows),
81
81
      resources(_resources),
82
82
#ifdef HAVE_NEPOMUK
83
 
      m_nepomukInitCalled(false),
 
83
      m_nepomukInitialized(false),
 
84
      m_nepomukWatcher(0),
84
85
#endif
85
86
      q(parent),
86
87
      ksmserverInterface(0)
90
91
    kDebug() << "-------------------------------------------------------";
91
92
 
92
93
#ifdef HAVE_NEPOMUK
93
 
    Nepomuk::ResourceManager::instance()->init();
 
94
    if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.nepomuk.services.nepomukstorage"))) {
 
95
        QTimer::singleShot(500, this, SLOT(nepomukOnline()));
 
96
 
 
97
    } else {
 
98
        m_nepomukWatcher = new QDBusServiceWatcher(QLatin1String("org.kde.nepomuk.services.nepomukstorage"),
 
99
                            QDBusConnection::sessionBus(),
 
100
                            QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
 
101
                            this);
 
102
        connect(m_nepomukWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(nepomukOnline()));
 
103
        connect(m_nepomukWatcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(nepomukOffline()));
 
104
    }
94
105
#endif
95
106
 
96
107
    // Initializing config
308
319
void ActivityManagerPrivate::syncActivitiesWithNepomuk()
309
320
{
310
321
#ifdef HAVE_NEPOMUK
 
322
    if (!nepomukInitialized()) return;
 
323
 
311
324
    foreach (const QString & activityId, activities.keys()) {
312
325
        Nepomuk::Resource activityResource(activityId, KEXT::Activity());
313
326
 
337
350
}
338
351
 
339
352
/* lazy init of nepomuk */
340
 
bool ActivityManagerPrivate::nepomukInitialized()
341
 
{
342
 
    if (m_nepomukInitCalled) return
343
 
        Nepomuk::ResourceManager::instance()->initialized();
344
 
 
345
 
    m_nepomukInitCalled = true;
346
 
 
347
 
    connect(Nepomuk::ResourceManager::instance(), SIGNAL(nepomukSystemStarted()), this, SLOT(backstoreAvailable()));
348
 
 
349
 
    return (Nepomuk::ResourceManager::instance()->init() == 0);
350
 
}
351
 
 
352
 
void ActivityManagerPrivate::backstoreAvailable()
353
 
{
354
 
    //emit q->BackstoreAvailable();
355
 
    //kick the icons, so that clients don't need to know that they depend on nepomuk
356
 
    for (QHash<QString, ActivityManager::State>::const_iterator i = activities.constBegin();
357
 
         i != activities.constEnd(); ++i) {
358
 
        emit q->ActivityChanged(i.key());
359
 
    }
360
 
}
361
 
 
362
 
#else // HAVE_NEPOMUK
363
 
 
364
 
void ActivityManagerPrivate::backstoreAvailable()
365
 
{
 
353
bool ActivityManagerPrivate::nepomukInitialized() const
 
354
{
 
355
    return m_nepomukInitialized;
366
356
}
367
357
 
368
358
#endif // HAVE_NEPOMUK
651
641
    transitioningActivity.clear();
652
642
}
653
643
 
 
644
void ActivityManagerPrivate::nepomukOnline()
 
645
{
 
646
#ifdef HAVE_NEPOMUK
 
647
    Nepomuk::ResourceManager::instance()->init();
 
648
 
 
649
    for (QHash<QString, ActivityManager::State>::const_iterator i = activities.constBegin();
 
650
         i != activities.constEnd(); ++i) {
 
651
        emit q->ActivityChanged(i.key());
 
652
    }
 
653
 
 
654
    m_nepomukInitialized = true;
 
655
#endif
 
656
}
 
657
 
 
658
void ActivityManagerPrivate::nepomukOffline()
 
659
{
 
660
#ifdef HAVE_NEPOMUK
 
661
    m_nepomukInitialized = false;
 
662
#endif
 
663
}
 
664
 
654
665
int ActivityManager::ActivityState(const QString & id) const
655
666
{
656
667
    //kDebug() << id << "- is it in" << d->activities << "?";
789
800
    kDebug() << "New event on the horizon" << application << windowId << event << uri;
790
801
 
791
802
#ifdef HAVE_NEPOMUK
792
 
    if (uri.startsWith("nepomuk:")) {
 
803
    if (NEPOMUK_RUNNING && uri.startsWith("nepomuk:")) {
793
804
        Nepomuk::Resource resource(kuri);
794
805
 
795
806
        if (resource.hasProperty(NIE::url())) {
830
841
    d->resources[kuri].mimetype = mimetype;
831
842
 
832
843
#ifdef HAVE_NEPOMUK
833
 
    Nepomuk::Resource resource(kuri);
834
 
    if (!resource.hasProperty(NIE::mimeType())) {
835
 
        kDebug() << "Setting the mime in nepomuk for" << uri << "to be" << mimetype;
836
 
        resource.setProperty(NIE::mimeType(), mimetype);
837
 
 
838
 
        if (mimetype.startsWith("image/")) {
839
 
            resource.addType(NFO::Image());
840
 
 
841
 
        } else if (mimetype.startsWith("video/")) {
842
 
            resource.addType(NFO::Video());
843
 
 
844
 
        } else if (mimetype.startsWith("audio/")) {
845
 
            resource.addType(NFO::Audio());
846
 
 
847
 
        } else if (mimetype.startsWith("image/")) {
848
 
            resource.addType(NFO::Image());
849
 
 
850
 
        } else if (mimetype.startsWith("text/")) {
851
 
            if (!resource.hasType(NFO::Bookmark())) {
852
 
                resource.addType(NFO::TextDocument());
853
 
 
854
 
                if (mimetype == "text/plain") {
855
 
                    resource.addType(NFO::PlainTextDocument());
856
 
 
857
 
                } else if (mimetype == "text/html") {
858
 
                        resource.addType(NFO::HtmlDocument());
 
844
    if (NEPOMUK_RUNNING) {
 
845
        Nepomuk::Resource resource(kuri);
 
846
        if (!resource.hasProperty(NIE::mimeType())) {
 
847
            kDebug() << "Setting the mime in nepomuk for" << uri << "to be" << mimetype;
 
848
            resource.setProperty(NIE::mimeType(), mimetype);
 
849
 
 
850
            if (mimetype.startsWith("image/")) {
 
851
                resource.addType(NFO::Image());
 
852
 
 
853
            } else if (mimetype.startsWith("video/")) {
 
854
                resource.addType(NFO::Video());
 
855
 
 
856
            } else if (mimetype.startsWith("audio/")) {
 
857
                resource.addType(NFO::Audio());
 
858
 
 
859
            } else if (mimetype.startsWith("image/")) {
 
860
                resource.addType(NFO::Image());
 
861
 
 
862
            } else if (mimetype.startsWith("text/")) {
 
863
                if (!resource.hasType(NFO::Bookmark())) {
 
864
                    resource.addType(NFO::TextDocument());
 
865
 
 
866
                    if (mimetype == "text/plain") {
 
867
                        resource.addType(NFO::PlainTextDocument());
 
868
 
 
869
                    } else if (mimetype == "text/html") {
 
870
                            resource.addType(NFO::HtmlDocument());
 
871
                    }
859
872
                }
860
873
            }
861
874
        }
862
 
 
863
875
    }
864
876
#endif
865
877
}
876
888
    d->resources[kuri].title = title;
877
889
 
878
890
#ifdef HAVE_NEPOMUK
879
 
    kDebug() << "Setting the title for" << uri << "to be" << title;
880
 
    Nepomuk::Resource resource(kuri);
 
891
    if (NEPOMUK_RUNNING) {
 
892
        kDebug() << "Setting the title for" << uri << "to be" << title;
 
893
        Nepomuk::Resource resource(kuri);
881
894
 
882
 
    kDebug() << uri << "local?" << kuri.isLocalFile()
883
 
                    << "title"  << resource.hasProperty(NIE::title());
884
 
    if (!kuri.isLocalFile() || !resource.hasProperty(NIE::title())) {
885
 
        resource.setProperty(NIE::title(), title);
 
895
        kDebug() << uri << "local?" << kuri.isLocalFile()
 
896
                        << "title"  << resource.hasProperty(NIE::title());
 
897
        if (!kuri.isLocalFile() || !resource.hasProperty(NIE::title())) {
 
898
            resource.setProperty(NIE::title(), title);
 
899
        }
886
900
    }
887
901
#endif
888
902
}
890
904
void ActivityManager::LinkResourceToActivity(const QString & uri, const QString & activity)
891
905
{
892
906
#ifdef HAVE_NEPOMUK
893
 
    if (!d->nepomukInitialized()) return;
 
907
    if (!NEPOMUK_RUNNING) return;
894
908
 
895
909
    kDebug() << "Linking" << uri << "to" << activity << CurrentActivity();
896
910