diff options
Diffstat (limited to 'lumina-desktop/desktop-plugins')
10 files changed, 570 insertions, 0 deletions
diff --git a/lumina-desktop/desktop-plugins/LDPlugin.h b/lumina-desktop/desktop-plugins/LDPlugin.h new file mode 100644 index 00000000..e8a1f5f3 --- /dev/null +++ b/lumina-desktop/desktop-plugins/LDPlugin.h @@ -0,0 +1,59 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is the generic container layout for all desktop plugins +// Simply subclass this when creating a new plugin to enable correct +// visibility and usage within the desktop window +//=========================================== +// WARNING: Do *not* setup a custom context menu for plugins! +// This can prevent access to the general desktop context menu if +// the plugin was maximized to fill the desktop area! +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_H + +#include <QObject> +#include <QWidget> +#include <QString> +#include <QDebug> +#include <QSettings> +#include <QMoveEvent> +#include <QResizeEvent> + +class LDPlugin : public QWidget{ + Q_OBJECT + +private: + QString PLUGID; + +public: + QSettings *settings; + + LDPlugin(QWidget *parent = 0, QString id="unknown") : QWidget(parent){ + PLUGID=id; + settings = new QSettings("desktop-plugins",PLUGID); + } + + ~LDPlugin(){ + delete settings; + } + + QString ID(){ + return PLUGID; + } + +public slots: + virtual void LocaleChange(){ + //This needs to be re-implemented in the subclassed plugin + //This is where all text is set/translated + } + virtual void ThemeChange(){ + //This needs to be re-implemented in the subclassed plugin + //This is where all the visuals are set if using Theme-dependant icons. + } +}; + +#endif
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/LDPluginContainer.h b/lumina-desktop/desktop-plugins/LDPluginContainer.h new file mode 100644 index 00000000..52e426ba --- /dev/null +++ b/lumina-desktop/desktop-plugins/LDPluginContainer.h @@ -0,0 +1,110 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is the generic container for a desktop plugin that handles +// saving/restoring all the movement and sizing +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H + +#include <QObject> +#include <QMdiSubWindow> +#include <QSettings> +#include <QMoveEvent> +#include <QResizeEvent> +#include <QCloseEvent> +#include <QString> +#include <QFile> + +#include "LDPlugin.h" + +class LDPluginContainer : public QMdiSubWindow{ + Q_OBJECT + +private: + QSettings *settings; + bool locked, setup; + +public: + LDPluginContainer(LDPlugin *plugin = 0, bool islocked = true) : QMdiSubWindow(){ + locked = islocked; + setup=true; + this->setWhatsThis(plugin->ID()); + if(locked){ this->setWindowFlags(Qt::FramelessWindowHint); } + else{ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); } + settings = plugin->settings; //save this pointer for access later + if(settings->allKeys().isEmpty()){ + //Brand new plugin - no location/size info saved yet + //save the initial size of the plugin - the initial location will be set automatically + settings->setValue("location/width", plugin->sizeHint().width()); + settings->setValue("location/height", plugin->sizeHint().height()); + settings->sync(); + } + this->setContentsMargins(0,0,0,0); + if(!locked){ + //this->setWindowTitle( plugin->ID().replace("---"," - ") ); + //this->setWidget( new QWidget() ); + this->setWidget( plugin ); + }else{ + this->setStyleSheet("LDPluginContainer{ background: transparent; border: none;}"); + this->setWidget(plugin); + } + } + + ~LDPluginContainer(){ + } + + void loadInitialPosition(){ + QRect set(settings->value("location/x",-12345).toInt(), settings->value("location/y",-12345).toInt(), settings->value("location/width",this->widget()->sizeHint().width()).toInt(), settings->value("location/height",this->widget()->sizeHint().height()).toInt()); + //qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height(); + if(set.height() < 10){ set.setHeight(10); } //to prevent foot-shooting + if(set.width() < 10){ set.setWidth(10); } //to prevent foot-shooting + if(set.x()!=-12345 && set.y()!=-12345){ + //custom location specified + this->setGeometry(set); + }else{ + this->resize(set.width(), set.height()); + } + setup=false; //done with setup + } + +signals: + void PluginRemoved(QString); + +protected: + void moveEvent(QMoveEvent *event){ + //Save this location to the settings + if(!locked && !setup){ + //qDebug() << "DP Move:" << event->pos().x() << event->pos().y(); + settings->setValue("location/x", event->pos().x()); + settings->setValue("location/y", event->pos().y()); + settings->sync(); + } + } + + void resizeEvent(QResizeEvent *event){ + //Save this size info to the settings + if(!locked && !setup){ + //qDebug() << "DP Resize:" << event->size().width() << event->size().height(); + settings->setValue("location/width", event->size().width()); + settings->setValue("location/height", event->size().height()); + settings->sync(); + } + QMdiSubWindow::resizeEvent(event); //be sure to pass this event along to the container + } + + void closeEvent(QCloseEvent *event){ + if( !this->whatsThis().isEmpty() ){ + //Plugin removed by the user - delete the settings file + QFile::remove( settings->fileName() ); + emit PluginRemoved( this->whatsThis() ); + } + event->accept(); //continue closing the widget + } + +}; + +#endif diff --git a/lumina-desktop/desktop-plugins/NewDP.h b/lumina-desktop/desktop-plugins/NewDP.h new file mode 100644 index 00000000..0e225cb9 --- /dev/null +++ b/lumina-desktop/desktop-plugins/NewDP.h @@ -0,0 +1,38 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is the interface to load all the different desktop plugins +//=========================================== +#ifndef _LUMINA_DESKTOP_NEW_DESKTOP_PLUGIN_H +#define _LUMINA_DESKTOP_NEW_DESKTOP_PLUGIN_H + +#include <QDebug> + +//List all the individual plugin includes here +#include "LDPlugin.h" +#include "SamplePlugin.h" +#include "calendar/CalendarPlugin.h" +#include "applauncher/AppLauncherPlugin.h" + +class NewDP{ +public: + static LDPlugin* createPlugin(QString plugin, QWidget* parent=0){ + LDPlugin *plug = 0; + if(plugin.section("---",0,0)=="sample"){ + plug = new SamplePlugin(parent, plugin); + }else if(plugin.section("---",0,0)=="calendar"){ + plug = new CalendarPlugin(parent, plugin); + }else if(plugin.section("---",0,0)=="applauncher"){ + plug = new AppLauncherPlugin(parent, plugin); + }else{ + qWarning() << "Invalid Desktop Plugin:"<<plugin << " -- Ignored"; + } + return plug; + } + +}; + +#endif
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/SamplePlugin.h b/lumina-desktop/desktop-plugins/SamplePlugin.h new file mode 100644 index 00000000..4a790c2d --- /dev/null +++ b/lumina-desktop/desktop-plugins/SamplePlugin.h @@ -0,0 +1,38 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is a quick sample desktop plugin +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_SAMPLE_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_SAMPLE_H + +#include <QPushButton> +#include <QMessageBox> +#include <QVBoxLayout> +#include "LDPlugin.h" + +class SamplePlugin : public LDPlugin{ + Q_OBJECT +public: + SamplePlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ + this->setLayout( new QVBoxLayout()); + this->layout()->setContentsMargins(0,0,0,0); + button = new QPushButton("sample"); + this->layout()->addWidget(button); + connect(button, SIGNAL(clicked()), this, SLOT(showMessage()) ); + } + + ~SamplePlugin(){} + +private: + QPushButton *button; + +private slots: + void showMessage(){ + QMessageBox::information(this,"sample","sample desktop plugin works"); + } +}; +#endif diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h new file mode 100644 index 00000000..3a8e5da8 --- /dev/null +++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h @@ -0,0 +1,84 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is a quick sample desktop plugin +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_APPLICATION_LAUNCHER_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_APPLICATION_LAUNCHER_H + +#include <QToolButton> +#include <QInputDialog> +#include <QVBoxLayout> +#include <QProcess> +#include <QFile> +#include <QFileSystemWatcher> +#include <QTimer> + +#include "../LDPlugin.h" + +#include <LuminaXDG.h> + +class AppLauncherPlugin : public LDPlugin{ + Q_OBJECT +public: + AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ + this->setLayout( new QVBoxLayout()); + this->layout()->setContentsMargins(0,0,0,0); + button = new QToolButton(this); + button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + button->setIconSize(QSize(64,64)); + button->setAutoRaise(true); + this->layout()->addWidget(button); + connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); + watcher = new QFileSystemWatcher(this); + connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT( loadButton()) ); + QTimer::singleShot(1,this, SLOT(loadButton()) ); + } + + ~AppLauncherPlugin(){} + +private: + QToolButton *button; + QFileSystemWatcher *watcher; + +private slots: + void loadButton(){ + QString path = this->settings->value("applicationpath","").toString(); + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(path, ok); + if(path.isEmpty() || !QFile::exists(path) || !ok){ + button->setWhatsThis(""); + button->setIcon( LXDG::findIcon("quickopen-file","") ); + button->setText( tr("Click to Set") ); + if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } + }else{ + button->setWhatsThis(file.filePath); + button->setIcon( LXDG::findIcon(file.icon,"quickopen") ); + button->setText( this->fontMetrics().elidedText(file.name, Qt::ElideRight, 64) ); + if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } + watcher->addPath(file.filePath); //make sure to update this shortcut if the file changes + } + } + + void buttonClicked(){ + QString path = button->whatsThis(); + if(path.isEmpty() || !QFile::exists(path) ){ + //prompt for the user to select an application + QList<XDGDesktop> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); + QStringList names; + for(int i=0; i<apps.length(); i++){ names << apps[i].name; } + bool ok = false; + QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok); + if(!ok || names.indexOf(app)<0){ return; } //cancelled + this->settings->setValue("applicationpath", apps[ names.indexOf(app) ].filePath); + QTimer::singleShot(0,this, SLOT(loadButton())); + }else{ + QProcess::startDetached("lumina-open "+path); + } + + } +}; +#endif diff --git a/lumina-desktop/desktop-plugins/calendar/CalendarPlugin.h b/lumina-desktop/desktop-plugins/calendar/CalendarPlugin.h new file mode 100644 index 00000000..e861052e --- /dev/null +++ b/lumina-desktop/desktop-plugins/calendar/CalendarPlugin.h @@ -0,0 +1,31 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is a quick sample desktop plugin +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_CALENDAR_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_CALENDAR_H + +#include <QCalendarWidget> +#include <QVBoxLayout> +#include "../LDPlugin.h" + +class CalendarPlugin : public LDPlugin{ + Q_OBJECT +public: + CalendarPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ + this->setLayout( new QVBoxLayout()); + this->layout()->setContentsMargins(0,0,0,0); + cal = new QCalendarWidget(this); + this->layout()->addWidget(cal); + } + + ~CalendarPlugin(){} + +private: + QCalendarWidget *cal; +}; +#endif diff --git a/lumina-desktop/desktop-plugins/desktopview/DeskItem.cpp b/lumina-desktop/desktop-plugins/desktopview/DeskItem.cpp new file mode 100644 index 00000000..21b1d1f6 --- /dev/null +++ b/lumina-desktop/desktop-plugins/desktopview/DeskItem.cpp @@ -0,0 +1,50 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "DeskItem.h" + +DeskItem::DeskItem(QWidget *parent, QString itempath, int ssize) : QToolButton(parent){ + this->setFixedSize(ssize, ssize); + this->setWhatsThis(itempath); + this->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + this->setAutoRaise(true); + int txtheight = this->fontMetrics().height() *2; + this->setIconSize( QSize(ssize-txtheight, ssize-txtheight)); + connect(this, SIGNAL(clicked()), this, SLOT(RunItem()) ); + updateItem(); +} + +DeskItem::~DeskItem(){ + +} + +void DeskItem::updateItem(){ + QFileInfo info(this->whatsThis()); + QIcon ico; + QString txt; + if(info.isDir()){ + ico = LXDG::findIcon("folder",""); + txt = info.fileName(); + }else if(info.suffix()=="desktop"){ + bool ok = false; + XDGDesktop dsk = LXDG::loadDesktopFile(this->whatsThis(), ok); + if(ok){ + ico = LXDG::findIcon( dsk.icon ); + txt = dsk.name; + }else{ + ico = LXDG::findIcon("",""); + txt = info.fileName(); + } + }else{ + ico = LXDG::findIcon("application-x-zerosize",""); + txt = info.fileName(); + } + this->setIcon(ico); + //Trim the text size to fit + txt = this->fontMetrics().elidedText(txt, Qt::ElideRight ,this->width() - 4); + this->setText(txt); + +}
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/desktopview/DeskItem.h b/lumina-desktop/desktop-plugins/desktopview/DeskItem.h new file mode 100644 index 00000000..c578d692 --- /dev/null +++ b/lumina-desktop/desktop-plugins/desktopview/DeskItem.h @@ -0,0 +1,30 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_ITEM_H +#define _LUMINA_DESKTOP_DESKTOP_ITEM_H + +#include <QToolButton> +#include <QProcess> +#include <QString> + +#include <LuminaXDG.h> + +class DeskItem : public QToolButton{ + Q_OBJECT +public: + DeskItem(QWidget *parent, QString itempath, int ssize); + ~DeskItem(); + + void updateItem(); + +private slots: + void RunItem(){ + QProcess::startDetached("lumina-open "+this->whatsThis()); + } +}; + +#endif
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp new file mode 100644 index 00000000..4c70d19f --- /dev/null +++ b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp @@ -0,0 +1,87 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "DesktopViewPlugin.h" + +DesktopViewPlugin::DesktopViewPlugin(QWidget *parent) : LDPlugin(parent, "desktopview"){ + watcher = new QFileSystemWatcher(this); + deskDir = QDir::homePath(); + if(QFile::exists(deskDir+"/Desktop") ){ + deskDir = deskDir+"/Desktop"; + }else if(QFile::exists(deskDir+"/desktop") ){ + deskDir = deskDir+"/desktop"; + } + watcher->addPath(deskDir); + icoSize = 0; //temporary placeholder + spacing = 0; //temporary placeholder + ITEMS.clear(); + layout = new QGridLayout(this); + layout->setContentsMargins(1,1,1,1); + this->setLayout(layout); + + //Connect the signals/slots + connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(UpdateDesktop()) ); + connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(UpdateDesktop()) ); + + //Now launch the update mechanisms in a new thread + QTimer::singleShot(10, this, SLOT(UpdateDesktop()) ); +} + +DesktopViewPlugin::~DesktopViewPlugin(){ + +} + +void DesktopViewPlugin::UpdateDesktop(){ + //Calculate available rows/columns + int oldSize = icoSize; + icoSize = 64; //64x64 default icons for now (make dynamic later) + int oldspacing = spacing; + spacing = 4; // 4 pixel space between items (make dynamic later); + if(icoSize != oldSize || spacing != oldspacing){ + //Re-create all the items with the proper size + for(int i=0; i<ITEMS.length(); i++){ + delete ITEMS.takeAt(i); //delete the widget + i--; + } + } + layout->setSpacing(spacing); + + int rmax = (this->height()-2)/(icoSize+spacing); + int cmax = (this->width()-2)/(icoSize+spacing); + //Now get the current items in the folder + QDir dir(deskDir); + QStringList items = dir.entryList( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Type | QDir::LocaleAware | QDir::DirsFirst); + //iterate over all current items + for(int i=0; i<ITEMS.length(); i++){ + int index = items.indexOf( ITEMS[i]->whatsThis().section("/",-1) ); + if( index == -1 ){ + //item no longer exists - remove it + delete ITEMS.takeAt(i); + i--; + }else{ + //Item still exists - remove it from the "new" list + ITEMS[i]->updateItem(); + items.removeAt(index); + } + } + //Now iterate over the spaces in the widget and create items as necessary + for(int r=0; r<rmax; r++){ + layout->setRowMinimumHeight(r,icoSize); + for(int c=0; c<cmax && items.length() > 0; c++){ + if(r==0){ layout->setColumnMinimumWidth(c,icoSize); } + if(layout->itemAtPosition(r,c)==0 && items.length() > 0){ + //Empty spot, put the first new item here + DeskItem *it = new DeskItem(this, deskDir+"/"+items[0], icoSize); + items.removeAt(0); + layout->addWidget(it, r,c); + ITEMS << it; + } + } + } + if(layout->itemAtPosition(rmax,cmax)==0){ + layout->addWidget(new QWidget(this), rmax, cmax); //put an empty widget here as a placeholder + } +}
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h new file mode 100644 index 00000000..9702e6e4 --- /dev/null +++ b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h @@ -0,0 +1,43 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This class is the interface to load all the different desktop plugins +//=========================================== +#ifndef _LUMINA_DESKTOP_VIEW_PLUGIN_H +#define _LUMINA_DESKTOP_VIEW_PLUGIN_H + +#include <QDir> +#include <QFile> +#include <QFileSystemWatcher> +#include <QGridLayout> +#include <QStringList> +#include <QList> +#include <QTimer> + +#include <LuminaXDG.h> + +#include "../LDPlugin.h" +#include "DeskItem.h" + + +class DesktopViewPlugin : public LDPlugin{ + Q_OBJECT +public: + DesktopViewPlugin(QWidget *parent = 0); + ~DesktopViewPlugin(); + +private: + QString deskDir; + QFileSystemWatcher *watcher; + QGridLayout *layout; + int icoSize, spacing; + QList<DeskItem*> ITEMS; + +private slots: + void UpdateDesktop(); + +}; +#endif
\ No newline at end of file |