~ubuntu-branches/ubuntu/saucy/plasma-netbook/saucy

« back to all changes in this revision

Viewing changes to shells/standaloneplasmoids/plasmaapp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-08-21 14:51:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821145150-i2dq75lekbfqopga
Tags: 0.0~svn1014174-0ubuntu1
* New svn snapshot
  - Put the applets in an horizontal layout
  - Cashew/newspaper fixes
  - New shell that will be used to load plasmoids as standalone apps
* Correctly version debhelper build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2006-2008 Aaron Seigo <aseigo@kde.org>
 
3
 *   Copyright 2009 Marco Martin <notmart@gmail.com>
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU Library General Public License as
 
7
 *   published by the Free Software Foundation; either version 2, or
 
8
 *   (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 Library General Public
 
16
 *   License along with this program; if not, write to the
 
17
 *   Free Software Foundation, Inc.,
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "plasmaapp.h"
 
22
 
 
23
#include <unistd.h>
 
24
 
 
25
#include <QApplication>
 
26
#include <QPixmapCache>
 
27
#include <QTimer>
 
28
#include <QVBoxLayout>
 
29
#include <QtDBus/QtDBus>
 
30
 
 
31
#include <KAction>
 
32
#include <KCrash>
 
33
#include <KDebug>
 
34
#include <KCmdLineArgs>
 
35
#include <KStandardAction>
 
36
#include <KWindowSystem>
 
37
 
 
38
#include <Plasma/Containment>
 
39
#include <Plasma/Theme>
 
40
#include <Plasma/Corona>
 
41
#include <Plasma/Applet>
 
42
 
 
43
#include "singleview.h"
 
44
 
 
45
 
 
46
PlasmaApp* PlasmaApp::self()
 
47
{
 
48
    if (!kapp) {
 
49
        return new PlasmaApp();
 
50
    }
 
51
 
 
52
    return qobject_cast<PlasmaApp*>(kapp);
 
53
}
 
54
 
 
55
PlasmaApp::PlasmaApp()
 
56
    : KUniqueApplication(),
 
57
      m_corona(0)
 
58
{
 
59
    KGlobal::locale()->insertCatalog("plasma-standaloneplasmoids");
 
60
    KCrash::setFlags(KCrash::AutoRestart);
 
61
 
 
62
 
 
63
    KConfigGroup cg(KGlobal::config(), "General");
 
64
    Plasma::Theme::defaultTheme()->setFont(cg.readEntry("desktopFont", font()));
 
65
 
 
66
    corona();
 
67
    //newInstance();
 
68
    connect(this, SIGNAL(aboutToQuit()), this, SLOT(cleanup()));
 
69
}
 
70
 
 
71
PlasmaApp::~PlasmaApp()
 
72
{
 
73
}
 
74
 
 
75
int  PlasmaApp::newInstance()
 
76
{
 
77
    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
 
78
 
 
79
    QString pluginName;
 
80
    if (args->count() > 0) {
 
81
        pluginName = args->arg(0);
 
82
    }
 
83
 
 
84
    QVariantList appletArgs;
 
85
    for (int i = 1; i < args->count(); ++i) {
 
86
        appletArgs << args->arg(i);
 
87
    }
 
88
 
 
89
    args->clear();
 
90
 
 
91
    SingleView *view = new SingleView(m_corona, pluginName, appletArgs);
 
92
    m_views.append(view);
 
93
    view->show();
 
94
}
 
95
 
 
96
 
 
97
void PlasmaApp::cleanup()
 
98
{
 
99
    if (m_corona) {
 
100
        m_corona->saveLayout();
 
101
    }
 
102
 
 
103
    qDeleteAll(m_views);
 
104
 
 
105
    delete m_corona;
 
106
    m_corona = 0;
 
107
 
 
108
    //TODO: This manual sync() should not be necessary?
 
109
    syncConfig();
 
110
}
 
111
 
 
112
void PlasmaApp::syncConfig()
 
113
{
 
114
    KGlobal::config()->sync();
 
115
}
 
116
 
 
117
 
 
118
Plasma::Corona* PlasmaApp::corona()
 
119
{
 
120
    if (!m_corona) {
 
121
        m_corona = new Plasma::Corona(this);
 
122
        connect(m_corona, SIGNAL(configSynced()), this, SLOT(syncConfig()));
 
123
 
 
124
 
 
125
        m_corona->setItemIndexMethod(QGraphicsScene::NoIndex);
 
126
        //m_corona->initializeLayout();
 
127
 
 
128
    }
 
129
 
 
130
    return m_corona;
 
131
}
 
132
 
 
133
bool PlasmaApp::hasComposite()
 
134
{
 
135
    return KWindowSystem::compositingActive();
 
136
}
 
137
 
 
138
 
 
139
bool PlasmaApp::eventFilter(QObject * watched, QEvent *event)
 
140
{
 
141
    return false;
 
142
}
 
143
 
 
144
#include "plasmaapp.moc"