From 1bafe0633b84676adf0c7f2d5f3113d021e81939 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 24 May 2017 21:01:43 -0400 Subject: Add in New Dir, New File, and Paste functionality to the desktop itself (if it represents the desktop folder), and also verify that the monitor ID migrator works properly when the single-monitor id changes between sessions. --- src-qt5/core/lumina-desktop/LDesktop.cpp | 109 ++++++++++++++++++++- src-qt5/core/lumina-desktop/LDesktop.h | 14 ++- .../applauncher/AppLauncherPlugin.cpp | 3 +- 3 files changed, 120 insertions(+), 6 deletions(-) (limited to 'src-qt5/core/lumina-desktop') diff --git a/src-qt5/core/lumina-desktop/LDesktop.cpp b/src-qt5/core/lumina-desktop/LDesktop.cpp index 01529b43..37bc7ffa 100644 --- a/src-qt5/core/lumina-desktop/LDesktop.cpp +++ b/src-qt5/core/lumina-desktop/LDesktop.cpp @@ -6,6 +6,8 @@ //=========================================== #include "LDesktop.h" #include "LSession.h" +#include +#include #include #include @@ -19,13 +21,13 @@ LDesktop::LDesktop(int deskNum, bool setdefault) : QObject(){ screenID = QApplication::screens().at(deskNum)->name(); DPREFIX = "desktop-"+screenID+"/"; - //desktopnumber = deskNum; - //desktop = QApplication::desktop(); + i_dlg_folder = true; + inputDLG = 0; defaultdesktop = setdefault; //(desktop->screenGeometry(desktopnumber).x()==0); //desktoplocked = true; issyncing = bgupdating = false; usewinmenu=false; - + desktopFolderActionMenu = 0; //Setup the internal variables settings = new QSettings(QSettings::UserScope, "lumina-desktop","desktopsettings", this); //qDebug() << " - Desktop Settings File:" << settings->fileName(); @@ -39,6 +41,7 @@ LDesktop::LDesktop(int deskNum, bool setdefault) : QObject(){ LDesktop::~LDesktop(){ delete deskMenu; delete winMenu; + delete desktopFolderActionMenu; //delete bgWindow; delete workspacelabel; delete wkspaceact; @@ -247,6 +250,13 @@ void LDesktop::InitDesktop(){ connect(bgDesktop, SIGNAL(DecreaseIcons()), this, SLOT(DecreaseDesktopPluginIcons()) ); connect(bgDesktop, SIGNAL(HideDesktopMenu()), deskMenu, SLOT(hide())); connect(bgDesktop, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowMenu()) ); + + desktopFolderActionMenu = new QMenu(0); + desktopFolderActionMenu->setTitle(tr("Desktop Actions")); + desktopFolderActionMenu->setIcon(LXDG::findIcon("user-desktop","")); + desktopFolderActionMenu->addAction(LXDG::findIcon("folder-new",""), tr("New Folder"), this, SLOT(NewDesktopFolder()) ); + desktopFolderActionMenu->addAction(LXDG::findIcon("document-new",""), tr("New File"), this, SLOT(NewDesktopFile()) ); + desktopFolderActionMenu->addAction(LXDG::findIcon("edit-paste",""), tr("Paste"), this, SLOT(PasteInDesktop()) ); if(DEBUG){ qDebug() << " - Desktop Init Done:" << screenID; } //Start the update processes QTimer::singleShot(10,this, SLOT(UpdateMenu()) ); @@ -318,6 +328,11 @@ void LDesktop::UpdateMenu(bool fast){ } } } + //Now add the desktop folder options (if desktop is icon-enabled) + if(settings->value(DPREFIX+"generateDesktopIcons",false).toBool()){ + deskMenu->addSeparator(); + deskMenu->addMenu(desktopFolderActionMenu); + } //Now add the system quit options deskMenu->addSeparator(); deskMenu->addAction(LXDG::findIcon("system-log-out",""), tr("Leave"), this, SLOT(SystemLogout()) ); @@ -570,3 +585,91 @@ void LDesktop::UpdateBackground(){ } bgupdating=false; } + +//Desktop Folder Interactions +void LDesktop::i_dlg_finished(int ret){ + if(inputDLG==0){ return; } + QString name = inputDLG->textValue(); + inputDLG->deleteLater(); + inputDLG = 0; + if(name.isEmpty() || ret!=QDialog::Accepted){ return; } //do nothing + if(i_dlg_folder){ NewDesktopFolder(name); } + else{ NewDesktopFile(name); } +} + +void LDesktop::NewDesktopFolder(QString name){ + if(name.isEmpty()){ + i_dlg_folder = true; //creating a new folder + if(inputDLG == 0){ + inputDLG = new QInputDialog(0, Qt::Dialog | Qt::WindowStaysOnTopHint); + inputDLG->setInputMode(QInputDialog::TextInput); + inputDLG->setTextValue(""); + inputDLG->setTextEchoMode(QLineEdit::Normal); + inputDLG->setLabelText( tr("New Folder") ); + connect(inputDLG, SIGNAL(finished(int)), this, SLOT(i_dlg_finished(int)) ); + } + inputDLG->showNormal(); + }else{ + QDir desktop(QDir::homePath()); + if(desktop.exists(tr("Desktop"))){ desktop.cd(tr("Desktop")); } //translated folder + else{ desktop.cd("Desktop"); } //default/english folder + if(!desktop.exists(name)){ desktop.mkpath(name); } + } +} + +void LDesktop::NewDesktopFile(QString name){ + if(name.isEmpty()){ + i_dlg_folder = false; //creating a new file + if(inputDLG == 0){ + inputDLG = new QInputDialog(0, Qt::Dialog | Qt::WindowStaysOnTopHint); + inputDLG->setInputMode(QInputDialog::TextInput); + inputDLG->setTextValue(""); + inputDLG->setTextEchoMode(QLineEdit::Normal); + inputDLG->setLabelText( tr("New File") ); + connect(inputDLG, SIGNAL(finished(int)), this, SLOT(i_dlg_finished(int)) ); + } + inputDLG->showNormal(); + }else{ + QDir desktop(QDir::homePath()); + if(desktop.exists(tr("Desktop"))){ desktop.cd(tr("Desktop")); } //translated folder + else{ desktop.cd("Desktop"); } //default/english folder + if(!desktop.exists(name)){ + QFile file(desktop.absoluteFilePath(name)); + if(file.open(QIODevice::WriteOnly) ){ file.close(); } + } + } +} + +void LDesktop::PasteInDesktop(){ + const QMimeData *mime = QApplication::clipboard()->mimeData(); + QStringList files; + if(mime->hasFormat("x-special/lumina-copied-files")){ + files = QString(mime->data("x-special/lumina-copied-files")).split("\n"); + }else if(mime->hasUrls()){ + QList urls = mime->urls(); + for(int i=0; i #include #include +#include #include @@ -70,13 +71,15 @@ private: QList PANELS; LDesktopPluginSpace *bgDesktop; //desktop plugin area //QWidget *bgWindow; //full screen background - QMenu *deskMenu, *winMenu; + QMenu *deskMenu, *winMenu, *desktopFolderActionMenu; QLabel *workspacelabel; QWidgetAction *wkspaceact; QList PLUGINS; QString CBG; //current background QRect globalWorkRect; - + bool i_dlg_folder; //folder/file switch + QInputDialog *inputDLG; + private slots: void InitDesktop(); void SettingsChanged(); @@ -103,5 +106,12 @@ private slots: void UpdateDesktopPluginArea(); //make sure the area is not underneath any panels void UpdateBackground(); + + //Desktop Folder Interactions + void i_dlg_finished(int ret); + void NewDesktopFolder(QString name = ""); + void NewDesktopFile(QString name = ""); + void PasteInDesktop(); + }; #endif diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp index 1730dbaa..266025c5 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp +++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp @@ -203,7 +203,8 @@ void AppLauncherPlugin::fileProperties(){ void AppLauncherPlugin::fileDelete(){ QString path = button->whatsThis(); if(path.isEmpty() || !QFile::exists(path)){ return; } //invalid file - QFile::remove(path); + if(QFileInfo(path).isDir()){ QProcess::startDetached("rm -r \""+path+"\""); } + else{ QFile::remove(path); } } void AppLauncherPlugin::fileCut(){ -- cgit