diff options
author | Ken Moore <ken@ixsystems.com> | 2017-05-24 21:01:43 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-05-24 21:01:43 -0400 |
commit | 1bafe0633b84676adf0c7f2d5f3113d021e81939 (patch) | |
tree | 4d50cc149383132f5796695479503e2c1712e949 | |
parent | Switch the usage of compton: default to it being disabled rather than enabled... (diff) | |
download | lumina-1bafe0633b84676adf0c7f2d5f3113d021e81939.tar.gz lumina-1bafe0633b84676adf0c7f2d5f3113d021e81939.tar.bz2 lumina-1bafe0633b84676adf0c7f2d5f3113d021e81939.zip |
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.
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktop.cpp | 109 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktop.h | 14 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp | 3 |
3 files changed, 120 insertions, 6 deletions
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 <QClipboard> +#include <QMimeData> #include <LuminaOS.h> #include <LuminaX11.h> @@ -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<QUrl> urls = mime->urls(); + for(int i=0; i<urls.length(); i++){ + files << QString("copy::::")+urls[i].toLocalFile(); + } + } + //Now go through and paste all the designated files + QString desktop = QDir::homePath()+"/"+tr("Desktop"); //translated form + if(!QFile::exists(desktop)){ desktop = QDir::homePath()+"/Desktop"; } //default/untranslated form + for(int i=0; i<files.length(); i++){ + QString path = files[i].section("::::",1,-1); + if(!QFile::exists(path)){ continue; } //does not exist any more - move on to next + QString newpath = desktop+"/"+path.section("/",-1); + if(QFile::exists(newpath)){ + //Need to change the filename a bit to make it unique + int n = 2; + newpath = desktop+"/"+QString::number(n)+"_"+path.section("/",-1); + while(QFile::exists(newpath)){ n++; newpath = desktop+"/"+QString::number(n)+"_"+path.section("/",-1); } + } + bool isdir = QFileInfo(path).isDir(); + if(files[i].section("::::",0,0)=="cut"){ + QFile::rename(path, newpath); + }else{ //copy + if(isdir){ QFile::link(path, newpath); } //symlink for directories - never do a full copy + else{ QFile::copy(path, newpath); } + } + } +} diff --git a/src-qt5/core/lumina-desktop/LDesktop.h b/src-qt5/core/lumina-desktop/LDesktop.h index b6034c18..e999911d 100644 --- a/src-qt5/core/lumina-desktop/LDesktop.h +++ b/src-qt5/core/lumina-desktop/LDesktop.h @@ -21,6 +21,7 @@ #include <QMdiArea> #include <QMdiSubWindow> #include <QRegion> +#include <QInputDialog> #include <LuminaXDG.h> @@ -70,13 +71,15 @@ private: QList<LPanel*> PANELS; LDesktopPluginSpace *bgDesktop; //desktop plugin area //QWidget *bgWindow; //full screen background - QMenu *deskMenu, *winMenu; + QMenu *deskMenu, *winMenu, *desktopFolderActionMenu; QLabel *workspacelabel; QWidgetAction *wkspaceact; QList<LDPlugin*> 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(){ |