diff options
Diffstat (limited to 'src-qt5')
37 files changed, 624 insertions, 365 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/LSession.cpp b/src-qt5/core/lumina-desktop-unified/LSession.cpp index e1251c01..ed4d644b 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.cpp +++ b/src-qt5/core/lumina-desktop-unified/LSession.cpp @@ -22,6 +22,7 @@ QThread* Lumina::EVThread = 0; RootWindow* Lumina::ROOTWIN = 0; XDGDesktopList* Lumina::APPLIST = 0; LShortcutEvents* Lumina::SHORTCUTS = 0; +DesktopManager* Lumina::DESKMAN = 0; LSession::LSession(int &argc, char ** argv) : LSingleApplication(argc, argv, "lumina-desktop-unified"){ //Initialize the global objects to null pointers @@ -49,10 +50,11 @@ LSession::LSession(int &argc, char ** argv) : LSingleApplication(argc, argv, "lu Lumina::NEF = new NativeEventFilter(); Lumina::NWS = new NativeWindowSystem(); Lumina::SS = new LScreenSaver(); + Lumina::DESKMAN = new DesktopManager(); //Now put the Native Window System into it's own thread to keep things snappy Lumina::EVThread = new QThread(); - //Lumina::NWS->moveToThread(Lumina::EVThread); - //Lumina::EVThread->start(); + Lumina::DESKMAN->moveToThread(Lumina::EVThread); + Lumina::EVThread->start(); Lumina::APPLIST = XDGDesktopList::instance(); Lumina::ROOTWIN = new RootWindow(); Lumina::SHORTCUTS = new LShortcutEvents(); //this can be moved to it's own thread eventually as well @@ -73,6 +75,7 @@ LSession::~LSession(){ if(DesktopSettings::instance()!=0){ DesktopSettings::instance()->deleteLater(); } if(Lumina::ROOTWIN!=0){ Lumina::ROOTWIN->deleteLater(); } if(Lumina::APPLIST!=0){ Lumina::APPLIST->deleteLater(); } + if(Lumina::DESKMAN!=0){ Lumina::DESKMAN->deleteLater(); } } void LSession::setupSession(){ @@ -104,6 +107,10 @@ void LSession::setupSession(){ splash.showScreen("user"); if(DEBUG){ qDebug() << " - Init User Files:" << timer->elapsed();} //checkUserFiles(); //adds these files to the watcher as well + Lumina::NWS->setRoot_numberOfWorkspaces(QStringList() << "one" << "two"); + Lumina::NWS->setRoot_currentWorkspace(0); + + Lumina::DESKMAN->start(); Lumina::ROOTWIN->start(); //Initialize the internal variables //DESKTOPS.clear(); @@ -124,14 +131,12 @@ void LSession::setupSession(){ //Initialize the desktops splash.showScreen("desktop"); - if(DEBUG){ qDebug() << " - Init Desktops:" << timer->elapsed(); } + /*if(DEBUG){ qDebug() << " - Init Desktops:" << timer->elapsed(); } QList<QScreen*> scrns= QApplication::screens(); for(int i=0; i<scrns.length(); i++){ qDebug() << " --- Load Wallpaper for Screen:" << scrns[i]->name(); RootDesktopObject::instance()->ChangeWallpaper(scrns[i]->name(),QUrl::fromLocalFile(LOS::LuminaShare()+"desktop-background.jpg").toString() ); - } - Lumina::NWS->setRoot_numberOfWorkspaces(QStringList() << "one" << "two"); - Lumina::NWS->setRoot_currentWorkspace(0); + }*/ if(DEBUG){ qDebug() << " - Create Desktop Context Menu"; } diff --git a/src-qt5/core/lumina-desktop-unified/global-objects.h b/src-qt5/core/lumina-desktop-unified/global-objects.h index c204587f..4cea60c2 100644 --- a/src-qt5/core/lumina-desktop-unified/global-objects.h +++ b/src-qt5/core/lumina-desktop-unified/global-objects.h @@ -22,9 +22,10 @@ //#include "src-events/LXcbEventFilter.h" //#endif #include "src-events/LShortcutEvents.h" - +#include "src-desktop/DesktopManager.h" #include "src-screensaver/LScreenSaver.h" //#include "src-WM/LWindowManager.h" + #include <RootWindow.h> #include "LSession.h" @@ -43,13 +44,13 @@ namespace Lumina{ //extern EventFilter *EFILTER; //Native Event Watcher extern LShortcutEvents *SHORTCUTS; //Keyboard/mouse shortcut events - //extern DesktopSettings *SETTINGS; //All Settings files + //ScreenSaver extern LScreenSaver *SS; //Root Window extern RootWindow *ROOTWIN; - //Window Manager - //LWindowManager *WM; + //Desktop Manager + extern DesktopManager *DESKMAN; //Application List extern XDGDesktopList *APPLIST; diff --git a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro index ebc13b6f..bb987e25 100644 --- a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro @@ -24,7 +24,7 @@ include(../libLumina/ExternalProcess.pri) include(../../src-cpp/NativeWindow.pri) include(../libLumina/XDGMime.pri) -include(../../src-cpp/plugins-screensaver.pri) +include(../../src-cpp/plugins-base.pri) #include all the main individual source groups include(src-screensaver/screensaver.pri) diff --git a/src-qt5/core/lumina-desktop-unified/main.cpp b/src-qt5/core/lumina-desktop-unified/main.cpp index ed2b9b4c..3cf35e50 100644 --- a/src-qt5/core/lumina-desktop-unified/main.cpp +++ b/src-qt5/core/lumina-desktop-unified/main.cpp @@ -39,11 +39,11 @@ int main(int argc, char ** argv) QTime *timer=0; if(DEBUG){ timer = new QTime(); timer->start(); } if(DEBUG){ qDebug() << "Theme Init:" << timer->elapsed(); } - LuminaThemeEngine theme(&a); - QObject::connect(&theme, SIGNAL(updateIcons()), &a, SLOT(reloadIconTheme()) ); + /*LuminaThemeEngine theme(&a); + QObject::connect(&theme, SIGNAL(updateIcons()), &a, SLOT(reloadIconTheme()) );*/ if(DEBUG){ qDebug() << "Session Setup:" << timer->elapsed(); } QTimer::singleShot(0, &a, SLOT(setupSession()) ); - theme.refresh(); + //theme.refresh(); if(DEBUG){ qDebug() << "Exec Time:" << timer->elapsed(); delete timer;} int retCode = a.exec(); qDebug() << "Finished Closing Down Unified Lumina"; diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.cpp new file mode 100644 index 00000000..d6d06be9 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.cpp @@ -0,0 +1,139 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017-2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "DesktopManager.h" + +#include "global-objects.h" + +// === PUBLIC === +DesktopManager::DesktopManager(){ + +} + +DesktopManager::~DesktopManager(){ + +} + +void DesktopManager::start(){ + connect(DesktopSettings::instance(), SIGNAL(FileModified(DesktopSettings::File)), this, SLOT(settingsChanged(DesktopSettings::File)) ); + //Perform the initial load of the settings files + QTimer::singleShot(0, this, SLOT(updateDesktopSettings()) ); + QTimer::singleShot(0, this, SLOT(updatePanelSettings()) ); + QTimer::singleShot(0, this, SLOT(updatePluginSettings()) ); + QTimer::singleShot(0, this, SLOT(updateMenuSettings()) ); + QTimer::singleShot(0, this, SLOT(updateAnimationSettings()) ); +} + +void DesktopManager::stop(){ + disconnect(DesktopSettings::instance(), SIGNAL(FileModified(DesktopSettings::File)), this, SLOT(settingsChanged(DesktopSettings::File)) ); +} + +// === PRIVATE === +void DesktopManager::updateWallpaper(QString screen_id, int wkspace){ + QString current = RootDesktopObject::instance()->CurrentWallpaper(screen_id); + if(!current.isEmpty()){ current = QUrl(current).toLocalFile(); } //convert it back to the normal file syntax + //First find the list of options from the settings + //First look for a list that matches this exact screen/workspace combo + QStringList wpaperList = DesktopSettings::instance()->value(DesktopSettings::Desktop, "wallpapers/"+screen_id+"_wk_"+QString::number(wkspace), QStringList()).toStringList(); + //Next look for a list that matches this exact workspace + if(wpaperList.isEmpty()){ wpaperList= DesktopSettings::instance()->value(DesktopSettings::Desktop, "wallpapers/default_wk_"+QString::number(wkspace), QStringList()).toStringList(); } + //Next look for a list that matches this exact screen + if(wpaperList.isEmpty()){ wpaperList= DesktopSettings::instance()->value(DesktopSettings::Desktop, "wallpapers/"+screen_id, QStringList()).toStringList(); } + //Now look for a list that matches any screen/workspace + if(wpaperList.isEmpty()){ wpaperList= DesktopSettings::instance()->value(DesktopSettings::Desktop, "wallpapers/default", QStringList()).toStringList(); } + //Now use the failover wallpaper directory + if(wpaperList.isEmpty()){ wpaperList << LOS::LuminaShare()+"../wallpapers/lumina-nature"; } + //Wallpaper selection/randomization + if(wpaperList.count()==1 && wpaperList.first()==current){ return; } //nothing to do - just the same image + QString wpaper; + QStringList bgL = wpaperList; //need a copy at the moment - could change the entire list in a second (opening a dir for instance) + while(wpaper.isEmpty() || QFileInfo(wpaper).isDir()){ + QString prefix; + if(!wpaper.isEmpty()){ + //Got a directory - update the list of files and re-randomize the selection + QStringList imgs = LUtils::imageExtensions(true); + QDir tdir(wpaper); + prefix=wpaper+"/"; + bgL = tdir.entryList(imgs, QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + //If directory no longer has any valid images - remove it from list and try again + if(bgL.isEmpty()){ + wpaperList.removeAll(wpaper); //invalid directory - remove it from the list for the moment + bgL = wpaperList; //reset the list back to the original list (not within a directory) + } + } + //Verify that there are files in the list - otherwise use the default + if(bgL.isEmpty()){ wpaper="default"; break; } + int index = ( qrand() % bgL.length() ); + if(index== bgL.indexOf(current)){ //if the current wallpaper was selected by the randomization again + //Go to the next in the list + if(index < 0 || index >= bgL.length()-1){ index = 0; } //if invalid or last item in the list - go to first + else{ index++; } //go to next + } + wpaper = prefix+bgL[index]; + } + //Now go ahead and set the wallpaper in the screen object + if(wpaper.isEmpty() || wpaper=="default"){ wpaper = LOS::LuminaShare()+"desktop-background.jpg"; } //failover image + qDebug() << "Updating Wallpaper:" << screen_id << wpaper; + RootDesktopObject::instance()->ChangeWallpaper(screen_id,QUrl::fromLocalFile(wpaper).toString() ); +} + +void DesktopManager::updatePanels(QString panel_id){ + +} + +void DesktopManager::updatePlugins(QString plugin_id){ + +} + +// === PUBLIC SLOTS === +void DesktopManager::workspaceChanged(int wknum){ + qDebug() << "Got Workspace Changed:" << wknum; + +} + +void DesktopManager::settingsChanged(DesktopSettings::File type){ + switch(type){ + case DesktopSettings::Desktop: + QTimer::singleShot(0, this, SLOT(updateDesktopSettings()) ); + case DesktopSettings::Panels: + QTimer::singleShot(0, this, SLOT(updatePanelSettings()) ); + case DesktopSettings::Plugins: + QTimer::singleShot(0, this, SLOT(updatePluginSettings()) ); + case DesktopSettings::ContextMenu: + QTimer::singleShot(0, this, SLOT(updateMenuSettings()) ); + case DesktopSettings::Animation: + QTimer::singleShot(0, this, SLOT(updateAnimationSettings()) ); + default: + break; + //Do nothing - not a settings change we care about here + } +} + +// === PRIVATE SLOTS === +void DesktopManager::updateDesktopSettings(){ + qDebug() << "Update Desktop Settings..."; + QList<QScreen*> scrns= QApplication::screens(); + int wkspace = Lumina::NWS->currentWorkspace(); + for(int i=0; i<scrns.length(); i++){ updateWallpaper(scrns[i]->name(), wkspace); } + +} + +void DesktopManager::updatePanelSettings(){ + +} + +void DesktopManager::updatePluginSettings(){ + +} + +void DesktopManager::updateMenuSettings(){ + +} + +void DesktopManager::updateAnimationSettings(){ + +} + diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.h b/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.h new file mode 100644 index 00000000..df681afa --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/DesktopManager.h @@ -0,0 +1,44 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017-2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is the main class that updates the interface objects +// on-demand as settings files and other stuff changes +//=========================================== +#ifndef _LUMINA_DESKTOP_OBJECT_MANAGER_H +#define _LUMINA_DESKTOP_OBJECT_MANAGER_H + +#include <global-includes.h> + +class DesktopManager : public QObject { + Q_OBJECT +public: + DesktopManager(); + ~DesktopManager(); + + void start(); + void stop(); + +private: + void updateWallpaper(QString screen_id, int wkspace); + void updatePanels(QString panel_id); + void updatePlugins(QString plugin_id); + +public slots: + void workspaceChanged(int); + void settingsChanged(DesktopSettings::File); + +private slots: + void updateDesktopSettings(); + void updatePanelSettings(); + void updatePluginSettings(); + void updateMenuSettings(); + void updateAnimationSettings(); + +signals: + void PanelLocationsChanged(); //reserved screen space changed +}; + +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri b/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri index e4c4faeb..f4a6882d 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri @@ -1,8 +1,10 @@ QT *= gui widgets qml quick -SOURCES *= $${PWD}/RootWindow.cpp +SOURCES *= $${PWD}/RootWindow.cpp \ + $${PWD}/Desktopmanager.cpp -HEADERS *= $${PWD}/RootWindow.h +HEADERS *= $${PWD}/RootWindow.h \ + $${PWD}/DesktopManager.h #update the includepath so we can just #include as needed without paths INCLUDEPATH *= $${PWD} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp index 5750ac2d..4b01fa0d 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp @@ -129,5 +129,13 @@ void RootDesktopObject::ChangeWallpaper(QString screen, QString value){ } } +QString RootDesktopObject::CurrentWallpaper(QString screen){ + for(int i=0; i<s_objects.length(); i++){ + if(s_objects[i]->name()==screen){ return s_objects[i]->background();} + } + return ""; //unknown +} + + // === PRIVATE === diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h index 838b5f7d..7d5182c4 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h @@ -55,6 +55,7 @@ private: public slots: void updateScreens(); //rescan/update screen objects void ChangeWallpaper(QString screen, QString); + QString CurrentWallpaper(QString screen); private slots: diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp index 7c098887..aa3214a2 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp @@ -7,6 +7,9 @@ #include "SSBaseWidget.h" +//Relative directory to search along the XDG paths for screensavers +#define REL_DIR QString("/lumina-desktop/screensavers") + #define DEBUG 0 // ======== @@ -39,10 +42,10 @@ void SSBaseWidget::startPainting(){ stopPainting(); //If a random plugin - grab one of the known plugins if(plugType=="random"){ - QList<SSPlugin> valid = SSPluginSystem::findAllPlugins(); + QList<SSPlugin> valid = PluginSystem::findAllPlugins<SSPlugin>(REL_DIR); if(!valid.isEmpty()){ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin }else if(plugType!="none"){ - cplug = SSPluginSystem::findPlugin(plugType); + cplug = PluginSystem::findPlugin<SSPlugin>(plugType, REL_DIR); } if(DEBUG){ qDebug() << " - Screen Saver:" << plugType << cplug.scriptURL() << cplug.isValid(); } if(cplug.isValid()){ diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h index 72e02702..e0a03d17 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h @@ -10,6 +10,7 @@ #define _LUMINA_DESKTOP_SCREEN_SAVER_BASE_WIDGET_H #include "global-includes.h" +#include <plugins-base.h> #include <plugins-screensaver.h> class SSBaseWidget : public QQuickView{ @@ -25,8 +26,8 @@ public slots: void stopPainting(); private: - QString plugType; - SSPlugin cplug; + QString plugType; + SSPlugin cplug; QTimer *restartTimer; private slots: diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp index 47c6bfe1..3d901e8c 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp @@ -67,6 +67,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->actionUSB_Image->setEnabled(false); loadIcons(); ui->tree_contents->setHeaderLabels( QStringList() << tr("File") << tr("MimeType") << tr("Size")+" " ); + + preservePaths = false; } MainUI::~MainUI(){ @@ -296,7 +298,7 @@ void MainUI::simpleExtractFiles(){ void MainUI::autoArchiveFiles(){ qDebug() << "Auto Archive Files:" << aaFileList; ui->label_progress->setText(tr("Adding Items...")); - BACKEND->startAdd(aaFileList); + BACKEND->startAdd(aaFileList, true); } void MainUI::extractSelection(){ diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.h b/src-qt5/desktop-utils/lumina-archiver/MainUI.h index 1a9d287c..0a5c094c 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.h +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.h @@ -26,13 +26,14 @@ public: void LoadArguments(QStringList); void loadIcons(); + bool preservePaths; private: Ui::MainUI *ui; - Backend *BACKEND; - QStringList aaFileList, sxList; - QString sxPath, sxFile; - QTimer *delayClose; + Backend *BACKEND; + QStringList aaFileList, sxList; + QString sxPath, sxFile; + QTimer *delayClose; QTreeWidgetItem* findItem(QString path, QTreeWidgetItem *start = 0); bool cleanItems(QStringList list, QTreeWidgetItem *start = 0); //returns true if anything gets cleaned diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp index 5338efec..91e233d0 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp @@ -91,7 +91,7 @@ QString Backend::linkTo(QString file){ } //Modification routines -void Backend::startAdd(QStringList paths){ +void Backend::startAdd(QStringList paths, bool absolutePaths){ //if(paths.isEmpty() && !insertQueue.isEmpty()){ paths = insertQueue; } //load the queue if(paths.contains(filepath)){ paths.removeAll(filepath); } if(paths.isEmpty()){ return; } @@ -109,11 +109,12 @@ void Backend::startAdd(QStringList paths){ args << "-c" << "-a"; args << flags; //Now setup the parent dir - for(int i=0; i<paths.length(); i++){ - paths[i] = paths[i].section(parent,1,-1); - if(paths[i].startsWith("/")){ paths[i].remove(0,1); } - } - args << "-C" << parent; + if(!absolutePaths) { + for(int i=0; i<paths.length(); i++){ + paths[i] = paths[i].section(parent,1,-1); + if(paths[i].startsWith("/")){ paths[i].remove(0,1); } + } + args << "-C" << parent; } args << paths; if(QFile::exists(filepath)){ //append to existing args.replaceInStrings(filepath, tmpfilepath); diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h index 56a7dcfe..cb24a053 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h @@ -33,7 +33,7 @@ public: QString linkTo(QString file); //Modification routines - void startAdd(QStringList paths); + void startAdd(QStringList paths, bool absolutePaths = false); void startRemove(QStringList paths); void startExtract(QString path, bool overwrite, QString file=""); //path to dir, overwrite, optional file to extract (everything otherwise) void startExtract(QString path, bool overwrite, QStringList files); diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts index 5cdf9fa4..7ae80a69 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts @@ -16,7 +16,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation>Uddannelse</translation> + <translation>Læring</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> @@ -41,7 +41,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation>Videnskab</translation> + <translation>Naturvidenskab</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> @@ -56,7 +56,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation>Hjælpeværktøj</translation> + <translation>Redskab</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts index 9947da6d..1cba660b 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts @@ -6,67 +6,67 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="608"/> <source>Multimedia</source> - <translation type="unfinished"></translation> + <translation>Multimedia</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="609"/> <source>Development</source> - <translation type="unfinished"></translation> + <translation>Ontwikkeling</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation type="unfinished"></translation> + <translation>Onderwijs</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> <source>Games</source> - <translation type="unfinished"></translation> + <translation>Spellen</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="612"/> <source>Graphics</source> - <translation type="unfinished"></translation> + <translation>Grafisch</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="613"/> <source>Network</source> - <translation type="unfinished"></translation> + <translation>Netwerk</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="614"/> <source>Office</source> - <translation type="unfinished"></translation> + <translation>Kantoor</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation type="unfinished"></translation> + <translation>Wetenschappelijk</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> <source>Settings</source> - <translation type="unfinished"></translation> + <translation>Instellingen</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="617"/> <source>System</source> - <translation type="unfinished"></translation> + <translation>Systeem</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation type="unfinished"></translation> + <translation>Hulpmiddel</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> <source>Wine</source> - <translation type="unfinished"></translation> + <translation>Wine</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="620"/> <source>Unsorted</source> - <translation type="unfinished"></translation> + <translation>Ongesorteerd</translation> </message> </context> <context> @@ -75,22 +75,22 @@ <location filename="../mainUI.ui" line="14"/> <location filename="../mainUI.cpp" line="53"/> <source>Calculator</source> - <translation type="unfinished"></translation> + <translation>Rekenmachine</translation> </message> <message> <location filename="../mainUI.ui" line="657"/> <source>Advanced Operations</source> - <translation type="unfinished"></translation> + <translation>Geavanceerde bewerkingen</translation> </message> <message> <location filename="../mainUI.cpp" line="83"/> <source>Percentage %1</source> - <translation type="unfinished"></translation> + <translation>Percentage %1</translation> </message> <message> <location filename="../mainUI.cpp" line="85"/> <source>Power %1</source> - <translation type="unfinished"></translation> + <translation>Prestatie %1</translation> </message> <message> <location filename="../mainUI.cpp" line="87"/> diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts index 153a01b4..e26ecb58 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts @@ -6,67 +6,67 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="608"/> <source>Multimedia</source> - <translation type="unfinished"></translation> + <translation>Multimídia</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="609"/> <source>Development</source> - <translation type="unfinished"></translation> + <translation>Desenvolvimento</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation type="unfinished"></translation> + <translation>Educação</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> <source>Games</source> - <translation type="unfinished"></translation> + <translation>Jogos</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="612"/> <source>Graphics</source> - <translation type="unfinished"></translation> + <translation>Gráficos</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="613"/> <source>Network</source> - <translation type="unfinished"></translation> + <translation>Rede</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="614"/> <source>Office</source> - <translation type="unfinished"></translation> + <translation>Escritório</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation type="unfinished"></translation> + <translation>Ciência</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> <source>Settings</source> - <translation type="unfinished"></translation> + <translation>Configurações</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="617"/> <source>System</source> - <translation type="unfinished"></translation> + <translation>Sistema</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation type="unfinished"></translation> + <translation>Utilitários</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> <source>Wine</source> - <translation type="unfinished"></translation> + <translation>Wine</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="620"/> <source>Unsorted</source> - <translation type="unfinished"></translation> + <translation>Não classificado</translation> </message> </context> <context> diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 7a25357a..be00e675 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -1,9 +1,8 @@ #include "PrintWidget.h" -PrintWidget::PrintWidget(QPrinter* printer, QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), +PrintWidget::PrintWidget(QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView), zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true) { - this->printer = printer; this->setMouseTracking(true); QList<QWidget*> children = this->findChildren<QWidget*>("",Qt::FindChildrenRecursively); for(int i=0; i<children.length(); i++){ @@ -68,7 +67,7 @@ void PrintWidget::setViewMode(ViewMode mode) { this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio); fitting = false; zoomMode = CustomZoom; - zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY()); + //zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY()); } else { fitting = true; fit(); @@ -121,23 +120,15 @@ void PrintWidget::setCurrentPage(int pageNumber) { } } +void PrintWidget::highlightText(int pageNum, QRectF textBox) { + PageItem *item = static_cast<PageItem*>(pages[pageNum]); + QPainter painter(this); + painter.fillRect(textBox, QColor(255, 255, 177, 128)); +} + //Private functions void PrintWidget::generatePreview() { - qDebug() << "generating preview"; - if(!previewEngine) - previewEngine = new QPreviewPaintEngine(); - if(!pdfEngine) - pdfEngine = new QPdfPrintEngine(QPrinter::HighResolution); - - printer->setEngines(previewEngine, previewEngine); - previewEngine->setProxyEngines(pdfEngine, pdfEngine); - - emit paintRequested(printer); - - printer->setEngines(pdfEngine, pdfEngine); - - qDebug() << "Populating Scene"; populateScene(); // i.e. setPreviewPrintedPictures() e.l. layoutPages(); curPage = qBound(1, curPage, pages.count()); @@ -153,13 +144,9 @@ void PrintWidget::layoutPages() { int numPagePlaces = numPages; int cols = 1; // singleMode and default if (viewMode == AllPagesView) { - if (printer->orientation() == QPrinter::Portrait) - cols = qCeil(qSqrt(numPages)); - else - cols = qFloor(qSqrt(numPages)); + cols = ((pictures->value(0)).width() > (pictures->value(0)).height()) ? qFloor(qSqrt(numPages)) : qCeil(qSqrt(numPages)); cols += cols % 2; // Nicer with an even number of cols - } - else if (viewMode == FacingPagesView) { + } else if (viewMode == FacingPagesView) { cols = 2; numPagePlaces += 1; } @@ -186,21 +173,19 @@ void PrintWidget::populateScene() scene->removeItem(pages.at(i)); qDeleteAll(pages); pages.clear(); - qDebug() << "Pages cleared"; int numPages = pictures->count(); - QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size(); - QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); - qDebug() << "Fields set"; + //Replace from loadingHash resolution + QSize paperSize = pictures->value(0).size(); + qDebug() << "Image paperSize" << paperSize; for (int i = 0; i < numPages; i++) { - PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize, pageRect); + PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize); scene->addItem(item); pages.append(item); } } - //Private Slots void PrintWidget::updateCurrentPage() { if (viewMode == AllPagesView) @@ -282,9 +267,13 @@ void PrintWidget::fit(bool doFitting) { } } - zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); + //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); } void PrintWidget::setPictures(QHash<int, QImage> *hash) { pictures = hash; } + +void PrintWidget::setOrientation(QPageLayout::Orientation ori) { + this->orientation = ori; +} diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h index 81e4e794..62543e45 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -18,18 +18,18 @@ #include <QScrollBar> #include <QStyleOptionGraphicsItem> #include <QtMath> -#include <QPrinter> +#include <QPageLayout> + namespace { class PageItem : public QGraphicsItem { public: - PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize, QRect _pageRect) + PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize) : pageNum(_pageNum), pagePicture(_pagePicture), - paperSize(_paperSize), pageRect(_pageRect) + paperSize(_paperSize) { - qreal border = qMax(paperSize.height(), paperSize.width()) / 25; - brect = QRectF(QPointF(-border, -border), - QSizeF(paperSize)+QSizeF(2*border, 2*border)); + brect = QRectF(QPointF(-25, -25), + QSizeF(paperSize)+QSizeF(50, 50)); setCacheMode(DeviceCoordinateCache); } @@ -45,7 +45,6 @@ private: int pageNum; const QImage pagePicture; QSize paperSize; - QRect pageRect; QRectF brect; }; @@ -78,17 +77,11 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->setClipRect(paperRect & option->exposedRect); painter->fillRect(paperRect, Qt::white); - if (pagePicture.isNull()) - return; - painter->drawImage(pageRect.topLeft(), pagePicture); - - // Effect: make anything drawn in the margins look washed out. - QPainterPath path; - path.addRect(paperRect); - path.addRect(pageRect); - painter->setPen(QPen(Qt::NoPen)); - painter->setBrush(QColor(255, 255, 255, 180)); - painter->drawPath(path); + if (pagePicture.isNull()){ + qDebug() << "NULL"; + return; + } + painter->drawImage(QPoint(0,0), pagePicture); } } @@ -96,7 +89,7 @@ class PrintWidget : public QGraphicsView { Q_OBJECT public: - PrintWidget(QPrinter *printer, QWidget *parent = 0); + PrintWidget(QWidget *parent = 0); ~PrintWidget(); enum ViewMode { SinglePageView, @@ -118,23 +111,25 @@ public: signals: void resized(); void customContextMenuRequested(const QPoint&); - void paintRequested(QPrinter*); public slots: void zoomIn(double factor=1.2); void zoomOut(double factor=1.2); void setCurrentPage(int); void setVisible(bool) Q_DECL_OVERRIDE; + void setOrientation(QPageLayout::Orientation); + void highlightText(int, QRectF); + void updatePreview(); void fitView(); void fitToWidth(); void setAllPagesViewMode(); void setSinglePageViewMode(); void setFacingPagesViewMode(); +private slots: void updateCurrentPage(); int calcCurrentPage(); void fit(bool doFitting=false); - void updatePreview(); protected: void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE { /*{ @@ -156,16 +151,14 @@ private: void setViewMode(ViewMode); void setZoomMode(ZoomMode); QGraphicsScene *scene; - QPrinter *printer; - QPreviewPaintEngine *previewEngine; - QPdfPrintEngine *pdfEngine; int curPage; ViewMode viewMode; ZoomMode zoomMode; + QPageLayout::Orientation orientation; double zoomFactor; bool initialized, fitting; - QList<QGraphicsItem *> pages; + QList<QGraphicsItem*> pages; QHash<int, QImage> *pictures; }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 4e65a766..57afbfe1 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -27,13 +27,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->setupUi(this); this->setWindowTitle(tr("Lumina PDF Viewer")); this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); - this->highlight = false; presentationLabel = 0; CurrentPage = 1; lastdir = QDir::homePath(); - Printer = new QPrinter(); //Create the interface widgets - WIDGET = new PrintWidget(Printer, this); + WIDGET = new PrintWidget(this); + WIDGET->setVisible(false); + WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); clockTimer = new QTimer(this); clockTimer->setInterval(1000); //1-second updates to clock connect(clockTimer, SIGNAL(timeout()), this, SLOT(updateClock()) ); @@ -52,13 +52,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ this->setCentralWidget(WIDGET); WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) ); - connect(WIDGET, &PrintWidget::paintRequested, this, - [=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); }); DOC = 0; connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); PrintDLG = new QPrintDialog(this); - //connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); + connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); //connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); //Create the other interface widgets @@ -231,17 +229,15 @@ void MainUI::loadFile(QString path){ Poppler::Page *PAGE = DOC->page(0); if(PAGE!=0){ lastdir = path.section("/",0,-2); //save this for later - Printer->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); - Printer->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Point); switch(PAGE->orientation()){ case Poppler::Page::Landscape: - Printer->setOrientation(QPrinter::Landscape); break; + WIDGET->setOrientation(QPageLayout::Landscape); break; default: - Printer->setOrientation(QPrinter::Portrait); + WIDGET->setOrientation(QPageLayout::Portrait); } delete PAGE; qDebug() << " - Document Setup : start loading pages now"; - startLoadingPages(Printer); + startLoadingPages(); //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview } @@ -253,7 +249,7 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q // Using Qt to scale the image (adjust page value) smooths out the image quite a bit without a lot of performance loss (but cannot scale up without pixelization) // The best approach seams to be to increase the DPI a bit, but match that with the same scaling on the page size (smoothing) - qDebug() << " - Render Page:" << num; + //qDebug() << " - Render Page:" << num; Poppler::Page *PAGE = doc->page(num); if(PAGE!=0){ //qDebug() << "DPI:" << dpi << "Size:" << page << "Page Size (pt):" << PAGE->pageSize(); @@ -263,7 +259,6 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q //qDebug() << " - Raw Image Size:" << raw.size(); loadingHash.insert(num, raw.scaled(scalefactor*page.width(), scalefactor*page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); raw = QImage(); //clear it - //qDebug() << "Page Label:" << num << PAGE->label(); /* QList<Annotation*> anno = PAGE->annotations(Annotations::AText ); QStringList annoS; @@ -382,7 +377,7 @@ void MainUI::endPresentation(){ this->releaseKeyboard(); } -void MainUI::startLoadingPages(QPrinter *printer){ +void MainUI::startLoadingPages(){ if(numPages>0){ return; } //currently loaded[ing] qDebug() << " - Start Loading Pages"; numPages = DOC->numPages(); @@ -390,17 +385,18 @@ void MainUI::startLoadingPages(QPrinter *printer){ progress->setRange(0,numPages); progress->setValue(0); progAct->setVisible(true); - QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); - QSize DPI(printer->resolution(),printer->resolution()); + QSizeF pageSize = DOC->page(0)->pageSizeF()*2; + //QSize DPI(loadingHash[0]->resolution(),loadingHash[0]->resolution()); + QSize DPI(76,76); /*qDebug() << "Screen Resolutions:"; QList<QScreen*> screens = QApplication::screens(); for(int i=0; i<screens.length(); i++){ qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY(); }*/ + qDebug() << "Poppler pageSize: " << pageSize; for(int i=0; i<numPages; i++){ - qDebug() << " - Kickoff page load:" << i; - //this->ccw = 0; - QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size()); + //qDebug() << " - Kickoff page load:" << i; + QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize); } } @@ -412,7 +408,8 @@ void MainUI::slotPageLoaded(int page){ progAct->setVisible(false); qDebug() << "Setting Pictures"; WIDGET->setPictures(&loadingHash); - QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); + WIDGET->setVisible(true); + //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //qDebug() << "Updating"; ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); @@ -426,52 +423,6 @@ void MainUI::slotPageLoaded(int page){ startPresentation(act == ui->actionAt_Beginning); }*/ -void MainUI::paintOnWidget(QPrinter *PRINTER, bool highlight){ - static bool first = true; - static bool shrunk = false; - if(DOC==0){ return; } - if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; } - //Increase the resolution of the page to match the image to prevent downscaling - if(first) - PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2)); - qDebug() << PRINTER->pageRect().size() << loadingHash[0].size() << WIDGET->size(); - QPainter painter(PRINTER); - painter.setPen(Qt::NoPen); - if(ui->findGroup->isVisible()) { - QSize size = PRINTER->pageRect().size(); - size = QSize(size.width(), size.height()-ui->findGroup->height()); - PRINTER->setPageSize(QPageSize(size)); - shrunk = true; - }else if(shrunk){ - QSize size = PRINTER->pageRect().size(); - size = QSize(size.width(), size.height()+ui->findGroup->height()); - PRINTER->setPageSize(QPageSize(size)); - shrunk = false; - } - if(highlight) { - Poppler::TextBox *currentText = results.keys()[currentHighlight]; - int pageNum = results.value(currentText), i; - - for(i = 0; i <= pageNum; i++) - if(i != 0){ PRINTER->newPage(); } - - qDebug() << pageNum << i; - this->highlight=false; - }else { - for(int i=0; i<numPages; i++){ - if(i != 0){ PRINTER->newPage(); } //this is the start of the next page (not needed for first) - if(loadingHash.contains(i)){ - painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(), - Qt::KeepAspectRatio, Qt::SmoothTransformation)); - } - else{ painter.drawImage(0,0, QImage()); } - } - WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); - //loadingHash.clear(); - first = false; - } -} - void MainUI::paintToPrinter(QPrinter *PRINTER){ if(loadingHash.keys().length() != numPages){ return; } @@ -561,9 +512,8 @@ void MainUI::rotate(bool ccw) { loadingHash.insert(i, image); } //Rotates the page as well as the image - Printer->setOrientation((Printer->orientation() == QPrinter::Landscape) ? - QPrinter::Portrait : QPrinter::Landscape); - + //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ? + //QPageLayout::Portrait : QPageLayout::Landscape); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); } @@ -664,9 +614,9 @@ void MainUI::find(QString text, bool forward) { Poppler::TextBox *currentText = results.keys()[currentHighlight]; WIDGET->setCurrentPage(results.value(currentText)); + WIDGET->highlightText(currentHighlight, currentText->boundingBox()); - QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); - this->highlight = true; + QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); }else{ //Print "No results found" } @@ -705,16 +655,3 @@ void MainUI::resizeEvent(QResizeEvent *event) { } QMainWindow::resizeEvent(event); } - -void MainUI::highlightText(QPrinter *PRINTER) { - Poppler::TextBox *currentText = results.keys()[currentHighlight]; - QPainter painter(PRINTER); - painter.setPen(Qt::NoPen); - int pageNum = results.value(currentText), i; - - for(i = 0; i <= pageNum; i++) - if(i != 0){ PRINTER->newPage(); } - - qDebug() << pageNum << i; - this->highlight=false; -} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index b3ad38f1..2d23b402 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -41,10 +41,9 @@ private: PrintWidget *WIDGET; Ui::MainUI *ui; PropDialog *PROPDIALOG; - QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; - bool matchCase, highlight; + bool matchCase; QMap<Poppler::TextBox*, int> results; int currentHighlight; @@ -62,7 +61,6 @@ private: int numPages; void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page); - void highlightText(QPrinter *PRINTER); //Functions/variables for the presentation mode PresentationLabel *presentationLabel; @@ -73,7 +71,7 @@ private: void endPresentation(); private slots: - void startLoadingPages(QPrinter *printer); + void startLoadingPages(); void slotPageLoaded(int); //void slotStartPresentation(QAction *act); @@ -85,12 +83,12 @@ private slots: void startPresentationHere(){ startPresentation(false); } void startPresentationBeginning(){ startPresentation(true); } void closePresentation(){ endPresentation(); } + void showInformation(); void find(QString text, bool forward); void enableFind(); void showBookmarks(); - void paintOnWidget(QPrinter*, bool); void paintToPrinter(QPrinter *PRINTER); //Button Slots diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 8626b2b4..b1592cc3 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -76,17 +76,22 @@ void PlainTextEditor::LoadFile(QString filepath){ bool diffFile = (filepath != this->whatsThis()); this->setWhatsThis(filepath); this->clear(); - QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); + /*QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); for(int i=0; i<files.length(); i++){ if(files[i].supportsFile(filepath) ){ files[i].SetupDocument(this); SYNTAX->loadRules(files[i]); break; } - } + }*/ //SYNTAX->loadRules( Custom_Syntax::ruleForFile(filepath.section("/",-1), settings) ); lastSaveContents = LUtils::readFile(filepath).join("\n"); if(diffFile){ + SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( lastSaveContents.section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); this->setPlainText( lastSaveContents ); }else{ //Try to keep the mouse cursor/scroll in the same position @@ -123,14 +128,18 @@ bool PlainTextEditor::SaveFile(bool newname){ if(file.isEmpty()){ return false; } //cancelled this->setWhatsThis(file); SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( this->toPlainText().section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); SYNTAX->rehighlight(); - readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag } if( !watcher->files().isEmpty() ){ watcher->removePaths(watcher->files()); } bool ok = LUtils::writeFile(this->whatsThis(), this->toPlainText().split("\n"), true); hasChanges = !ok; if(ok){ lastSaveContents = this->toPlainText(); emit FileLoaded(this->whatsThis()); } watcher->addPath(currentFile()); + readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag return true; //qDebug() << " - Success:" << ok << hasChanges; } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 53f51f4e..a80d4149 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -83,6 +83,16 @@ bool SyntaxFile::supportsFile(QString file){ return false; } +bool SyntaxFile::supportsFirstLine(QString line){ + line = line.simplified(); + if(metaObj.contains("first_line_match")){ + return metaObj.value("first_line_match").toArray().contains(line); + }else if(metaObj.contains("first_line_regex")){ + return (QRegExp( metaObj.value("first_line_regex").toString() ).indexIn(line) >=0 ); + } + return false; +} + bool SyntaxFile::LoadFile(QString file, QSettings *settings){ QStringList contents = LUtils::readFile(file); //Now trim the extra non-JSON off the beginning of the file @@ -209,6 +219,13 @@ QString Custom_Syntax::ruleForFile(QString filename, QSettings *settings){ return ""; } +QString Custom_Syntax::ruleForFirstLine(QString line, QSettings *settings){ + QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); + for(int i=0; i<files.length(); i++){ + if(files[i].supportsFirstLine(line)){ return files[i].name(); } + } + return ""; +} void Custom_Syntax::loadRules(QString type){ QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h index bffbfd1a..9949a90c 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h @@ -46,6 +46,7 @@ public: void SetupDocument(QPlainTextEdit *editor); bool supportsFile(QString file); //does this syntax set support the file? + bool supportsFirstLine(QString line); //is the type of file defined by the first line of the file? ("#!/bin/<something>" for instance) //Main Loading routine (run this before other functions) bool LoadFile(QString file, QSettings *settings); @@ -66,10 +67,13 @@ public: } ~Custom_Syntax(){} + QString loadedRules(){ return syntax.name(); } + static QStringList availableRules(QSettings *settings); static QStringList knownColors(); static void SetupDefaultColors(QSettings *settings); static QString ruleForFile(QString filename, QSettings *settings); + static QString ruleForFirstLine(QString line, QSettings *settings); void loadRules(QString type); void loadRules(SyntaxFile sfile); @@ -77,6 +81,8 @@ public: loadRules( syntax.name() ); } + void setupDocument(QPlainTextEdit *edit){ syntax.SetupDocument(edit); } //simple redirect for the function in the currently-loaded rules + protected: void highlightBlock(const QString &text){ //qDebug() << "Highlight Block:" << text; @@ -159,7 +165,7 @@ protected: int last = text.length()-1; while(last>=0 && (text[last]==' ' || text[last]=='\t' ) ){ last--; } if(last < text.length()-1){ - setFormat(last+1, text.length()-1-last, fmt); + setFormat(last+1, text.length()-1-last, fmt); } } } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md index fa00b557..04190672 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md @@ -9,9 +9,11 @@ A small comment section may be placed at the top of the file where every line st # Requirements 1. A "meta" object containing the following variables (meta information about the rules): 1. "name" : The name that will be shown to the user for this set of syntax rules. - 2. If this syntax file is to be automatically applied to particular file type, then one of the following options must be set: + 2. If this syntax file is to be automatically applied to particular file type, then at least one of the following options must be set: 1. "file_suffix" : An array of file extensions which are supported by this syntax rule set (Example: temp.foo will be matched by "file_suffix"=["foo"] ) 2. "file_regex" : A regular expression which should be used to find if the filename matches this rule set. + 3. "first_line_match" : *(only used if no filename rules matched)* Exact match for the first line of text in the file (Example: "#!/bin/sh") + 4. "first_line_regex" : *(only used if no filename rules matched)* Regular expression to use when find a match for the first line of text in the file 2. A "format" object containing the following variables (file-wide formatting): 1. "columns_per_line" : (integer, optional) For file formats with line-length restrictions, this will automatically highlight/flag any "overage" of the designated limit. 2. "highlight_whitespace_eol" : (boolian, optional) Highlight any excess whitespace at the end of a line. diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax index ab67d384..1982e599 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "JSON", - "file_suffix": ["json", "syntax"] + "file_suffix": ["json", "syntax"], + "first_line_match":["{"] }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax index 6690d98c..2145beec 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Python", - "file_suffix": ["py", "pyc"] + "file_suffix": ["py", "pyc"], + "first_line_regex" : "(#!).+(python)" }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax index 5f38cadc..f2256731 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Shell", - "file_suffix": ["sh"] + "file_suffix": ["sh"], + "first_line_match":["#!/bin/sh", "#!/sbin/openrc-run"] }, "format": { "line_wrap": false, diff --git a/src-qt5/src-cpp/plugins-base.cpp b/src-qt5/src-cpp/plugins-base.cpp new file mode 100644 index 00000000..f38374df --- /dev/null +++ b/src-qt5/src-cpp/plugins-base.cpp @@ -0,0 +1,50 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "plugins-base.h" + +// ============ +// Base PLUGIN +// ============ +BasePlugin::BasePlugin(){ + +} + +BasePlugin::~BasePlugin(){ + +} + +void BasePlugin::loadFile(QString path){ + data = QJsonObject(); + currentfile = path; + QFile file(path); + if(!file.exists() || !file.open(QIODevice::ReadOnly)){ return; } + data = QJsonDocument::fromJson(file.readAll()).object(); + //qDebug() << "Loaded ScreenSaver Data:" << currentfile << data; + file.close(); +} + +QString BasePlugin::translatedObject(QString obj){ + QJsonObject tmp = data.value(obj).toObject(); + //Get the current locale + QString locale = getenv("LC_ALL"); + if(locale.isEmpty()){ locale = getenv("LC_MEBaseAGES"); } + if(locale.isEmpty()){ locale = getenv("LANG"); } + if(locale.isEmpty()){ locale = "default"; } + if(locale.contains(".")){ locale = locale.section(".",0,0); } //chop any charset code off the end + //Now find which localized string is available and return it + if(tmp.contains(locale)){ return tmp.value(locale).toString(); } + locale = locale.section("_",0,0); //full locale not found - look for shortened form + if(tmp.contains(locale)){ return tmp.value(locale).toString(); } + return tmp.value("default").toString(); //use the default version +} + +QUrl BasePlugin::scriptURL(){ + QString exec = data.value("qml").toObject().value("exec").toString(); + if(!exec.startsWith("/")){ exec.prepend( currentfile.section("/",0,-2)+"/" ); } + return QUrl::fromLocalFile(exec); +} + diff --git a/src-qt5/src-cpp/plugins-base.h b/src-qt5/src-cpp/plugins-base.h new file mode 100644 index 00000000..26b0eacc --- /dev/null +++ b/src-qt5/src-cpp/plugins-base.h @@ -0,0 +1,107 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is a simple class for managing all the various desktop +// screensaver plugins that could be available +//=========================================== +// NOTE: +// This class has a heirarchy-based lookup system +// USER plugins > SYSTEM plugins +// XDG_DATA_HOME/lumina-desktop/screensavers > XDG_DATA_DIRS/lumina-desktop/screensavers +//=========================================== +#ifndef _LUMINA_DESKTOP_BASE_PLUGINS_CLASS_H +#define _LUMINA_DESKTOP_BASE_PLUGINS_CLASS_H + +#include <QJsonObject> +#include <QString> +#include <QUrl> +#include <QObject> +#include <QJsonDocument> +#include <QJsonArray> +#include <QFile> +#include <QDir> +#include <QDebug> + +class BasePlugin{ +protected: + QString currentfile; + +public: + BasePlugin(); + virtual ~BasePlugin(); + + virtual void loadFile(QString path); + bool isLoaded() { return !data.isEmpty(); }; + bool containsDefault(QString obj) { return data.value(obj).toObject().contains("default"); } + + /** + * Check if the plugin is valid as long as the JSON is not empty, + * it contains at least a "name", "qml", and "description" object, + * and the "name" and "description" objects contain a "default" key. + **/ + virtual bool isValid() = 0; + + virtual QString translatedObject(QString obj); + virtual QUrl scriptURL(); + + QJsonObject data; //Hazardous to manually modify + QString relDir; +}; + +class PluginSystem{ +public: + template <class T> + static T findPlugin(QString, QString); + + template <class T> + static QList<T> findAllPlugins(QString, bool validonly=true); +}; + +// =================== +// Base PLUGIN SYSTEM +// =================== +template <class T> +T PluginSystem::findPlugin(QString name, QString REL_DIR){ + //qDebug() << "FindPlugin:" << name; + T BaseP; + if(name.startsWith("/") && QFile::exists(name)){ BaseP.loadFile(name); return BaseP;} //absolute path give - just load that one + //Cleanup the input name and ensure it has the right suffix + name = name.section("/",-1); + if(!name.endsWith(".json")){ name.append(".json"); } + //Get the list of directories to search + QStringList dirs; + dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); + //Look for that file within these directories and return the first one found + for(int i=0; i<dirs.length(); i++){ + if(!QFile::exists(dirs[i]+REL_DIR+"/"+name)){ continue; } + BaseP.loadFile(dirs[i]+REL_DIR+"/"+name); + if(BaseP.isValid()){ break; } //got a good one - stop here + } + return BaseP; +} + +template <class T> +QList<T> PluginSystem::findAllPlugins(QString REL_DIR, bool validonly) { + QList<T> LIST; + //Get the list of directories to search + QStringList dirs; + dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); + //Look for that file within these directories and return the first one found + for(int i=0; i<dirs.length(); i++){ + if(!QFile::exists(dirs[i]+REL_DIR)){ continue; } + QDir dir(dirs[i]+REL_DIR); + QStringList files = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Name); + //qDebug() << "Found Files:" << files; + for(int j=0; j<files.length(); j++){ + T tmp; + tmp.loadFile(dir.absoluteFilePath(files[j])); + //qDebug() << "Loaded File:" << files[j] << tmp.isValid(); + if(!validonly || tmp.isValid()){ LIST << tmp; } + } + } + return LIST; +} +#endif diff --git a/src-qt5/src-cpp/plugins-base.pri b/src-qt5/src-cpp/plugins-base.pri new file mode 100644 index 00000000..4aa9d96e --- /dev/null +++ b/src-qt5/src-cpp/plugins-base.pri @@ -0,0 +1,8 @@ +HEADERS *= $${PWD}/plugins-base.h \ + $${PWD}/plugins-screensaver.h \ + $${PWD}/plugins-desktop.h +SOURCES *= $${PWD}/plugins-base.cpp \ + $${PWD}/plugins-screensaver.cpp \ + $${PWD}/plugins-desktop.cpp + +INCLUDEPATH *= $${PWD} diff --git a/src-qt5/src-cpp/plugins-desktop.cpp b/src-qt5/src-cpp/plugins-desktop.cpp new file mode 100644 index 00000000..fdbd676d --- /dev/null +++ b/src-qt5/src-cpp/plugins-desktop.cpp @@ -0,0 +1,40 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "plugins-desktop.h" + +// ============ +// DT PLUGIN +// ============ +DTPlugin::DTPlugin(){ + +} + +DTPlugin::~DTPlugin(){ + +} + +bool DTPlugin::isValid(){ + if(data.isEmpty()){ return false; } + bool ok = data.contains("name") && data.contains("qml") && data.contains("description"); + ok &= containsDefault("name"); + ok &= containsDefault("description"); + if(ok) { + QJsonObject tmp = data.value("qml").toObject(); + QStringList mustexist; + QString exec = tmp.value("exec").toString(); + if(exec.isEmpty() || !exec.endsWith(".qml")){ return false; } + mustexist << exec; + QJsonArray tmpA = data.value("additional_files").toArray(); + for(int i=0; i<tmpA.count(); i++){ mustexist << tmpA[i].toString(); } + QString reldir = currentfile.section("/",0,-2) + "/"; + for(int i=0; i<mustexist.length() && ok; i++){ + if(mustexist[i].startsWith("/")){ ok = QFile::exists(mustexist[i]); } + else { ok = QFile::exists(reldir+mustexist[i]); } + } + } + return ok; +} diff --git a/src-qt5/src-cpp/plugins-desktop.h b/src-qt5/src-cpp/plugins-desktop.h new file mode 100644 index 00000000..ed576db1 --- /dev/null +++ b/src-qt5/src-cpp/plugins-desktop.h @@ -0,0 +1,29 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGINS_CLASS_H +#define _LUMINA_DESKTOP_DESKTOP_PLUGINS_CLASS_H + +#include "plugins-base.h" +#include <QJsonObject> +#include <QString> +#include <QUrl> +#include <QObject> +#include <QJsonDocument> +#include <QJsonArray> +#include <QFile> +#include <QDir> +#include <QDebug> + +class DTPlugin : public BasePlugin{ +public: + DTPlugin(); + ~DTPlugin(); + + virtual bool isValid() Q_DECL_OVERRIDE; +}; + +#endif diff --git a/src-qt5/src-cpp/plugins-screensaver.cpp b/src-qt5/src-cpp/plugins-screensaver.cpp index 50796a52..6370b068 100644 --- a/src-qt5/src-cpp/plugins-screensaver.cpp +++ b/src-qt5/src-cpp/plugins-screensaver.cpp @@ -5,14 +5,6 @@ // See the LICENSE file for full details //=========================================== #include "plugins-screensaver.h" -#include <QJsonDocument> -#include <QJsonArray> -#include <QFile> -#include <QDir> -#include <QDebug> - -//Relative directory to search along the XDG paths for screensavers -#define REL_DIR QString("/lumina-desktop/screensavers") // ============ // SS PLUGIN @@ -25,35 +17,12 @@ SSPlugin::~SSPlugin(){ } -void SSPlugin::loadFile(QString path){ - data = QJsonObject(); - currentfile = path; - QFile file(path); - if(!file.exists() || !file.open(QIODevice::ReadOnly)){ return; } - data = QJsonDocument::fromJson(file.readAll()).object(); - //qDebug() << "Loaded ScreenSaver Data:" << currentfile << data; - file.close(); -} - -bool SSPlugin::isLoaded(){ - return !data.isEmpty(); -} - bool SSPlugin::isValid(){ if(data.isEmpty()){ return false; } bool ok = data.contains("name") && data.contains("qml") && data.contains("description"); - if(ok){ - //go to the next name level and see if required sub-items exist - QJsonObject tmp = data.value("name").toObject(); - ok = tmp.contains("default"); - } - if(ok){ - //go to the next description level and see if required sub-items exist - QJsonObject tmp = data.value("description").toObject(); - ok = tmp.contains("default"); - } -if(ok){ - //go to the next qml level and see if required sub-items exist + ok &= containsDefault("name"); + ok &= containsDefault("description"); + if(ok) { QJsonObject tmp = data.value("qml").toObject(); QStringList mustexist; QString exec = tmp.value("exec").toString(); @@ -62,7 +31,6 @@ if(ok){ QJsonArray tmpA = data.value("additional_files").toArray(); for(int i=0; i<tmpA.count(); i++){ mustexist << tmpA[i].toString(); } QString reldir = currentfile.section("/",0,-2) + "/"; - //qDebug() << "Got MustExist:" << mustexist << reldir; for(int i=0; i<mustexist.length() && ok; i++){ if(mustexist[i].startsWith("/")){ ok = QFile::exists(mustexist[i]); } else { ok = QFile::exists(reldir+mustexist[i]); } @@ -70,83 +38,3 @@ if(ok){ } return ok; } - -QString SSPlugin::translatedName(){ - QJsonObject tmp = data.value("name").toObject(); - //Get the current locale - QString locale = getenv("LC_ALL"); - if(locale.isEmpty()){ locale = getenv("LC_MESSAGES"); } - if(locale.isEmpty()){ locale = getenv("LANG"); } - if(locale.isEmpty()){ locale = "default"; } - if(locale.contains(".")){ locale = locale.section(".",0,0); } //chop any charset code off the end - //Now find which localized string is available and return it - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - locale = locale.section("_",0,0); //full locale not found - look for shortened form - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - return tmp.value("default").toString(); //use the default version -} - -QString SSPlugin::translatedDescription(){ - QJsonObject tmp = data.value("description").toObject(); - //Get the current locale - QString locale = getenv("LC_ALL"); - if(locale.isEmpty()){ locale = getenv("LC_MESSAGES"); } - if(locale.isEmpty()){ locale = getenv("LANG"); } - if(locale.isEmpty()){ locale = "default"; } - if(locale.contains(".")){ locale = locale.section(".",0,0); } //chop any charset code off the end - //Now find which localized string is available and return it - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - locale = locale.section("_",0,0); //full locale not found - look for shortened form - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - return tmp.value("default").toString(); //use the default version -} - -QUrl SSPlugin::scriptURL(){ - QString exec = data.value("qml").toObject().value("exec").toString(); - //qDebug() << "got exec:" << exec << data; - if(!exec.startsWith("/")){ exec.prepend( currentfile.section("/",0,-2)+"/" ); } - return QUrl::fromLocalFile(exec); -} - -// =================== -// SS PLUGIN SYSTEM -// =================== -SSPlugin SSPluginSystem::findPlugin(QString name){ - //qDebug() << "FindPlugin:" << name; - SSPlugin SSP; - if(name.startsWith("/") && QFile::exists(name)){ SSP.loadFile(name); return SSP;} //absolute path give - just load that one - //Cleanup the input name and ensure it has the right suffix - name = name.section("/",-1); - if(!name.endsWith(".json")){ name.append(".json"); } - //Get the list of directories to search - QStringList dirs; - dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); - //Look for that file within these directories and return the first one found - for(int i=0; i<dirs.length(); i++){ - if(!QFile::exists(dirs[i]+REL_DIR+"/"+name)){ continue; } - SSP.loadFile(dirs[i]+REL_DIR+"/"+name); - if(SSP.isValid()){ break; } //got a good one - stop here - } - return SSP; -} - -QList<SSPlugin> SSPluginSystem::findAllPlugins(bool validonly){ - QList<SSPlugin> LIST; - //Get the list of directories to search - QStringList dirs; - dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); - //Look for that file within these directories and return the first one found - for(int i=0; i<dirs.length(); i++){ - if(!QFile::exists(dirs[i]+REL_DIR)){ continue; } - QDir dir(dirs[i]+REL_DIR); - QStringList files = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Name); - //qDebug() << "Found Files:" << files; - for(int j=0; j<files.length(); j++){ - SSPlugin tmp; - tmp.loadFile(dir.absoluteFilePath(files[j])); - //qDebug() << "Loaded File:" << files[j] << tmp.isValid(); - if(!validonly || tmp.isValid()){ LIST << tmp; } - } - } - return LIST; -} diff --git a/src-qt5/src-cpp/plugins-screensaver.h b/src-qt5/src-cpp/plugins-screensaver.h index 9a7e98f5..042f824d 100644 --- a/src-qt5/src-cpp/plugins-screensaver.h +++ b/src-qt5/src-cpp/plugins-screensaver.h @@ -4,47 +4,26 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== -// This is a simple class for managing all the various desktop -// screensaver plugins that could be available -//=========================================== -// NOTE: -// This class has a heirarchy-based lookup system -// USER plugins > SYSTEM plugins -// XDG_DATA_HOME/lumina-desktop/screensavers > XDG_DATA_DIRS/lumina-desktop/screensavers -//=========================================== #ifndef _LUMINA_DESKTOP_SCREENSAVER_PLUGINS_CLASS_H #define _LUMINA_DESKTOP_SCREENSAVER_PLUGINS_CLASS_H +#include "plugins-base.h" #include <QJsonObject> #include <QString> #include <QUrl> #include <QObject> +#include <QJsonDocument> +#include <QJsonArray> +#include <QFile> +#include <QDir> +#include <QDebug> -class SSPlugin{ -private: - QString currentfile; - +class SSPlugin : public BasePlugin { public: - QJsonObject data; //Hazardous to manually modify - SSPlugin(); ~SSPlugin(); - void loadFile(QString path); - bool isLoaded(); - - bool isValid(); - - QString translatedName(); - QString translatedDescription(); - QUrl scriptURL(); -}; - -class SSPluginSystem{ -public: - static SSPlugin findPlugin(QString name); - static QList<SSPlugin> findAllPlugins(bool validonly = true); - + virtual bool isValid() Q_DECL_OVERRIDE; }; #endif diff --git a/src-qt5/src-cpp/plugins-screensaver.pri b/src-qt5/src-cpp/plugins-screensaver.pri deleted file mode 100644 index ad03f34c..00000000 --- a/src-qt5/src-cpp/plugins-screensaver.pri +++ /dev/null @@ -1,4 +0,0 @@ -HEADERS *= $${PWD}/plugins-screensaver.h -SOURCES *= $${PWD}/plugins-screensaver.cpp - -INCLUDEPATH *= $${PWD} |