diff --git a/shell/activityconfiguration/activityconfiguration.cpp b/shell/activityconfiguration/activityconfiguration.cpp index 0692a183..ff1c635c 100644 --- a/shell/activityconfiguration/activityconfiguration.cpp +++ b/shell/activityconfiguration/activityconfiguration.cpp @@ -1,331 +1,342 @@ /*************************************************************************** * Copyright 2010 Alexis Menard * * Copyright 2010 Artur Duque de Souza * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ //own #include "activityconfiguration.h" //Qt #include #include #include #include #include #include #include #include +#include +#include //KDE #include #include //Plasma #include #include #include #include #ifndef NO_ACTIVITIES #include #endif #include "backgroundlistmodel.h" #include "plasmaapp.h" ActivityConfiguration::ActivityConfiguration(QGraphicsWidget *parent) : Plasma::DeclarativeWidget(parent), m_containment(0), m_mainWidget(0), m_model(0), m_wallpaperIndex(-1), m_newContainment(false) { Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic"); m_package = new Plasma::Package(QString(), "org.kde.active.activityconfiguration", structure); //setInitializationDelayed(true); //setQmlPath(m_package->filePath("mainscript")); #ifndef NO_ACTIVITIES m_activityController = new KActivities::Controller(this); #endif Plasma::Wallpaper *wp = Plasma::Wallpaper::load(bestWallpaperPluginAvailable()); if (wp) { wp->setParent(this); wp->setTargetSizeHint(PlasmaApp::defaultScreenSize()); wp->setResizeMethodHint(Plasma::Wallpaper::ScaledAndCroppedResize); } m_model = new BackgroundListModel(wp, this); connect(m_model, SIGNAL(countChanged()), this, SLOT(modelCountChanged())); m_model->reload(); if (engine()) { QDeclarativeContext *ctxt = engine()->rootContext(); if (ctxt) { ctxt->setContextProperty("configInterface", this); } setQmlPath(m_package->filePath("mainscript")); m_mainWidget = qobject_cast(rootObject()); if (m_mainWidget) { - connect(m_mainWidget, SIGNAL(closeRequested()), - this, SLOT(deleteLater())); + connect(m_mainWidget, SIGNAL(closeRequested()), SLOT(doExit())); } } emit modelChanged(); } ActivityConfiguration::~ActivityConfiguration() { } +void ActivityConfiguration::doExit() +{ + QDBusMessage call = QDBusMessage::createMethodCall("org.kde.plasma-keyboardcontainer", + "/MainApplication", + "org.kde.plasma.VirtualKeyboard", + "hide"); + QDBusConnection::sessionBus().asyncCall(call); + deleteLater(); +} + void ActivityConfiguration::ensureContainmentExistence() { if (m_containment) { return; } #ifndef NO_ACTIVITIES const QString id = m_activityController->addActivity(m_activityName); m_activityController->setCurrentActivity(id); #endif Plasma::Corona *corona = qobject_cast(scene()); QEventLoop loop; //FIXME: find a better way // AJS: a better way would be to connect the new containment signal in Corona QTimer::singleShot(100, &loop, SLOT(quit())); loop.exec(); if (corona) { setContainment(corona->containmentForScreen(0)); } } void ActivityConfiguration::setContainment(Plasma::Containment *cont) { m_containment = cont; if (!m_containment) { // we are being setup for containment creation! m_newContainment = true; } if (m_containment) { m_activityName = m_containment->activity(); emit activityNameChanged(); } if (m_newContainment) { // reset this for the next time this dialog is used m_newContainment = false; } if (!m_containment) { return; } ensureContainmentHasWallpaperPlugin(); m_model->setTargetSizeHint(m_containment->size().toSize()); // save the wallpaper config so we can find the proper index later in modelCountChanged Plasma::Wallpaper *wp = m_containment->wallpaper(); if (wp) { // shoulw always be true: // can only be false on a broken system with no wallpapers able to show images KConfigGroup wpConfig = wallpaperConfig(); if (wpConfig.isValid()) { wp->save(wpConfig); } } } KConfigGroup ActivityConfiguration::wallpaperConfig() { if (!m_containment || !m_containment->wallpaper()) { return KConfigGroup(); } KConfigGroup wpConfig = m_containment->config(); wpConfig = KConfigGroup(&wpConfig, "Wallpaper"); wpConfig = KConfigGroup(&wpConfig, m_containment->wallpaper()->pluginName()); return wpConfig; } void ActivityConfiguration::modelCountChanged() { if (!m_containment || m_model->count() < 1) { return; } // since we're using the Image plugin, we'll cheat a bit and peek at the configuration // to see what wallpaper we're using QModelIndex index = m_model->indexOf(wallpaperConfig().readEntry("wallpaper", QString())); if (index.isValid()) { m_wallpaperIndex = index.row(); emit wallpaperIndexChanged(); } } Plasma::Containment *ActivityConfiguration::containment() const { return m_containment; } void ActivityConfiguration::setActivityName(const QString &name) { if (name == m_activityName) { return; } m_activityName = name; ensureContainmentExistence(); if (!m_containment) { //should never happen return; } m_containment->setActivity(name); emit activityNameChanged(); } QString ActivityConfiguration::activityName() const { return m_activityName; } QString ActivityConfiguration::activityId() const { if (!m_containment) { return QString(); } return m_containment->context()->currentActivityId(); } bool ActivityConfiguration::isActivityNameConfigurable() const { #ifndef NO_ACTIVITIES return true; #else return false; #endif } QObject *ActivityConfiguration::wallpaperModel() { return m_model; } int ActivityConfiguration::wallpaperIndex() { return m_wallpaperIndex; } void ActivityConfiguration::setWallpaperIndex(const int index) { ensureContainmentExistence(); if (!m_containment || !m_model) { //should never happen return; } if (m_wallpaperIndex == index || index < 0) { return; } m_wallpaperIndex = index; Plasma::Package *b = m_model->package(index); if (!b) { return; } QString wallpaper; if (b->structure()->contentsPrefixPaths().isEmpty()) { // it's not a full package, but a single paper wallpaper = b->filePath("preferred"); } else { wallpaper = b->path(); } kDebug()<<"Setting new wallpaper path:"<wallpaper()) { const QString mimetype = KMimeType::findByUrl(wallpaper).data()->name(); ensureContainmentHasWallpaperPlugin(mimetype); } if (m_containment->wallpaper()) { m_containment->wallpaper()->setUrls(KUrl::List() << wallpaper); KConfigGroup wpConfig = wallpaperConfig(); if (wpConfig.isValid()) { wpConfig.writeEntry("wallpaper", wallpaper); //m_containment->wallpaper()->save(wpConfig); } emit containmentWallpaperChanged(m_containment); } emit wallpaperIndexChanged(); } QString ActivityConfiguration::bestWallpaperPluginAvailable(const QString &mimetype) const { const KPluginInfo::List wallpaperList = Plasma::Wallpaper::listWallpaperInfoForMimetype(mimetype); if (wallpaperList.isEmpty()) { // this would be a rather broken system return QString(); } // we look for the image plugin, as that's really the one we want to default to foreach (const KPluginInfo &wallpaper, wallpaperList) { if (wallpaper.pluginName() == "image") { return "image"; } } // "image" doesn't exist, so we just return whatever was first in the list return wallpaperList.at(0).name(); } void ActivityConfiguration::ensureContainmentHasWallpaperPlugin(const QString &mimetype) { if (m_containment && (!m_containment->wallpaper() || !m_containment->wallpaper()->supportsMimetype(mimetype))) { m_containment->setWallpaper(bestWallpaperPluginAvailable()); } } QSize ActivityConfiguration::screenshotSize() { return m_model ? m_model->screenshotSize() : QSize(320, 280); } void ActivityConfiguration::setScreenshotSize(const QSize &size) { if (m_model) { m_model->setScreenshotSize(size); } } #include "activityconfiguration.moc" diff --git a/shell/activityconfiguration/activityconfiguration.h b/shell/activityconfiguration/activityconfiguration.h index c091c6f9..4a2f6b2a 100644 --- a/shell/activityconfiguration/activityconfiguration.h +++ b/shell/activityconfiguration/activityconfiguration.h @@ -1,103 +1,104 @@ /*************************************************************************** * Copyright 2011 Marco Martin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef PLASMA_ACTIVITYCONFIG_H #define PLASMA_ACTIVITYCONFIG_H #include class QDeclarativeItem; class PlasmaAppletItemModel; class BackgroundListModel; #include namespace KActivities { class Controller; } namespace Plasma { class Containment; class Package; } class ActivityConfiguration : public Plasma::DeclarativeWidget { Q_OBJECT Q_PROPERTY(QString activityName READ activityName WRITE setActivityName NOTIFY activityNameChanged) Q_PROPERTY(QString activityId READ activityId) Q_PROPERTY(QObject *wallpaperModel READ wallpaperModel NOTIFY modelChanged) Q_PROPERTY(int wallpaperIndex READ wallpaperIndex WRITE setWallpaperIndex NOTIFY wallpaperIndexChanged) Q_PROPERTY(QSize screenshotSize READ screenshotSize WRITE setScreenshotSize) Q_PROPERTY(bool activityNameConfigurable READ isActivityNameConfigurable) public: ActivityConfiguration(QGraphicsWidget *parent = 0); ~ActivityConfiguration(); void setContainment(Plasma::Containment *cont); Plasma::Containment *containment() const; void setActivityName(const QString &name); QString activityName() const; QString activityId() const; QObject *wallpaperModel(); int wallpaperIndex(); void setWallpaperIndex(const int index); QSize screenshotSize(); void setScreenshotSize(const QSize &size); bool isActivityNameConfigurable() const; Q_SIGNALS: void modelChanged(); void wallpaperIndexChanged(); void activityNameChanged(); void containmentAvailable(); void containmentWallpaperChanged(Plasma::Containment *containment); protected: void ensureContainmentExistence(); private: void ensureContainmentHasWallpaperPlugin(const QString &mimetype = "image/jpeg"); QString bestWallpaperPluginAvailable(const QString &wallpaper = "image/jpeg") const; KConfigGroup wallpaperConfig(); private Q_SLOTS: void modelCountChanged(); + void doExit(); private: Plasma::Containment *m_containment; QDeclarativeItem *m_mainWidget; BackgroundListModel *m_model; KActivities::Controller *m_activityController; Plasma::Package *m_package; QString m_activityName; int m_wallpaperIndex; bool m_newContainment; }; #endif //PLASMA_ACTIVITYCONFIG_H diff --git a/shell/widgetsexplorer/mobilewidgetsexplorer.cpp b/shell/widgetsexplorer/mobilewidgetsexplorer.cpp index d02e9ddf..d3508746 100644 --- a/shell/widgetsexplorer/mobilewidgetsexplorer.cpp +++ b/shell/widgetsexplorer/mobilewidgetsexplorer.cpp @@ -1,101 +1,113 @@ /*************************************************************************** * Copyright 2010 Alexis Menard * * Copyright 2010 Artur Duque de Souza * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ //own #include "mobilewidgetsexplorer.h" #include "plasmaappletitemmodel_p.h" //Qt #include #include #include #include #include #include +#include +#include //KDE #include #include //Plasma #include #include #include MobileWidgetsExplorer::MobileWidgetsExplorer(QGraphicsItem *parent) : QGraphicsWidget(parent), m_containment(0), m_mainWidget(0) { setContentsMargins(0, 0, 0, 0); m_declarativeWidget = new Plasma::DeclarativeWidget(this); QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(this); lay->setContentsMargins(0, 0, 0, 0); lay->addItem(m_declarativeWidget); m_appletsModel = new PlasmaAppletItemModel(this); m_appletsModel->setApplication(QString()); Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic"); m_package = new Plasma::Package(QString(), "org.kde.active.widgetexplorer", structure); m_declarativeWidget->setQmlPath(m_package->filePath("mainscript")); if (m_declarativeWidget->engine()) { QDeclarativeContext *ctxt = m_declarativeWidget->engine()->rootContext(); if (ctxt) { ctxt->setContextProperty("myModel", m_appletsModel); } m_mainWidget = qobject_cast(m_declarativeWidget->rootObject()); if (m_mainWidget) { connect(m_mainWidget, SIGNAL(addAppletRequested(const QString &)), this, SLOT(addApplet(const QString &))); - connect(m_mainWidget, SIGNAL(closeRequested()), this, SLOT(deleteLater())); + connect(m_mainWidget, SIGNAL(closeRequested()), SLOT(doExit())); } } } MobileWidgetsExplorer::~MobileWidgetsExplorer() { } +void MobileWidgetsExplorer::doExit() +{ + QDBusMessage call = QDBusMessage::createMethodCall("org.kde.plasma-keyboardcontainer", + "/MainApplication", + "org.kde.plasma.VirtualKeyboard", + "hide"); + QDBusConnection::sessionBus().asyncCall(call); + deleteLater(); +} + void MobileWidgetsExplorer::setContainment(Plasma::Containment *cont) { m_containment = cont; } Plasma::Containment *MobileWidgetsExplorer::containment() const { return m_containment; } void MobileWidgetsExplorer::addApplet(const QString &plugin) { if (m_mainWidget) { kWarning() << "Applet added" << plugin; if (m_containment) { m_containment->addApplet(plugin); } } } #include "mobilewidgetsexplorer.moc" diff --git a/shell/widgetsexplorer/mobilewidgetsexplorer.h b/shell/widgetsexplorer/mobilewidgetsexplorer.h index 94c3377d..3d1d2210 100644 --- a/shell/widgetsexplorer/mobilewidgetsexplorer.h +++ b/shell/widgetsexplorer/mobilewidgetsexplorer.h @@ -1,59 +1,60 @@ /*************************************************************************** * Copyright 2010 MArco Martin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef PLASMA_MOBILEWIDGETEXPLORER_H #define PLASMA_MOBILEWIDGETEXPLORER_H #include class QDeclarativeItem; class PlasmaAppletItemModel; namespace Plasma { class Containment; class DeclarativeWidget; class Package; } class MobileWidgetsExplorer : public QGraphicsWidget { Q_OBJECT public: MobileWidgetsExplorer(QGraphicsItem *parent); ~MobileWidgetsExplorer(); void setContainment(Plasma::Containment *cont); Plasma::Containment *containment() const; protected Q_SLOTS: void addApplet(const QString &plugin); + void doExit(); private: Plasma::Containment *m_containment; QDeclarativeItem *m_mainWidget; Plasma::DeclarativeWidget *m_declarativeWidget; Plasma::Package *m_package; PlasmaAppletItemModel *m_appletsModel; }; #endif //PLASMA_MOBILEWIDGETEXPLORER_H