From 086e63c81bc037fd255230313bffb4de907d8b97 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 26 Aug 2015 15:52:43 -0400 Subject: Add support for the "New [File/Dir]" buttons back into lumina-fm. --- lumina-fm/widgets/DirWidget.cpp | 50 +++++++++++++++++++++++++++++++++++- lumina-fm/widgets/DirWidget.h | 2 ++ lumina-fm/widgets/DirWidget.ui | 26 +++++++++++++++++++ lumina-fm/widgets/SlideshowWidget.ui | 16 ++++++++++-- 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp index 98589164..b13b73fa 100644 --- a/lumina-fm/widgets/DirWidget.cpp +++ b/lumina-fm/widgets/DirWidget.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -152,6 +154,8 @@ void DirWidget::LoadDir(QString dir, QList list){ //Hide the extra buttons for a moment ui->tool_goToPlayer->setVisible(false); ui->tool_goToImages->setVisible(false); + ui->tool_new_dir->setVisible(canmodify); + ui->tool_new_file->setVisible(canmodify); //Determine if this is an internal ZFS snapshot bool loadsnaps = false; if( dir.contains(ZSNAPDIR) ){ @@ -322,7 +326,9 @@ void DirWidget::UpdateIcons(){ ui->tool_snap_older->setIcon(LXDG::findIcon("go-previous-view","") ); //Bottom-Action Buttons ui->tool_goToImages->setIcon( LXDG::findIcon("fileview-preview","") ); - ui->tool_goToPlayer->setIcon( LXDG::findIcon("applications-multimedia","") ); + ui->tool_goToPlayer->setIcon( LXDG::findIcon("applications-multimedia","") ); + ui->tool_new_file->setIcon( LXDG::findIcon("document-new","") ); + ui->tool_new_dir->setIcon( LXDG::findIcon("folder-new","") ); //Side-Action Buttons ui->tool_act_run->setIcon( LXDG::findIcon("run-build-file","") ); ui->tool_act_runwith->setIcon( LXDG::findIcon("run-build-configure","") ); @@ -494,6 +500,48 @@ void DirWidget::on_tool_goToPlayer_clicked(){ } } +void DirWidget::on_tool_new_file_clicked(){ + if(!canmodify){ return; } //cannot create anything here + //Prompt for the new filename + bool ok = false; + QString newdocument = QInputDialog::getText(this, tr("New Document"), tr("Name:"), QLineEdit::Normal, "", \ + &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly); + if(!ok || newdocument.isEmpty()){ return; } + //Create the empty file + QString full = CDIR; + if(!full.endsWith("/")){ full.append("/"); } + QFile file(full+newdocument); + if(file.open(QIODevice::ReadWrite)){ + //If successfully opened, it has created a blank file + file.close(); + }else{ + QMessageBox::warning(this, tr("Error Creating Document"), tr("The document could not be created. Please ensure that you have the proper permissions.")); + } +} + +void DirWidget::on_tool_new_dir_clicked(){ + if(!canmodify){ return; } //cannot create anything here + //Prompt for the new dir name + bool ok = false; + QString newdir = QInputDialog::getText(this, tr("New Directory"), tr("Name:"), QLineEdit::Normal, "", \ + &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly); + if(!ok || newdir.isEmpty()){ return; } + //Now create the new dir + QString full = CDIR; + if(!full.endsWith("/")){ full.append("/"); } + QDir dir(full); //open the current dir + full.append(newdir); //append the new name to the current dir + //Verify that the new dir does not already exist + if(dir.exists(full)){ + QMessageBox::warning(this, tr("Invalid Name"), tr("A file or directory with that name already exists! Please pick a different name.")); + QTimer::singleShot(0,this, SLOT(on_tool_addToDir_clicked()) ); //repeat this function + }else{ + if(!dir.mkdir(newdir) ){ + QMessageBox::warning(this, tr("Error Creating Directory"), tr("The directory could not be created. Please ensure that you have the proper permissions to modify the current directory.")); + } + } +} + // -- Top Snapshot Buttons void DirWidget::on_tool_snap_newer_clicked(){ ui->slider_snap->setValue( ui->slider_snap->value()+1 ); diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h index 193d1789..c5dab371 100644 --- a/lumina-fm/widgets/DirWidget.h +++ b/lumina-fm/widgets/DirWidget.h @@ -99,6 +99,8 @@ private slots: // -- Bottom Action Buttons void on_tool_goToImages_clicked(); void on_tool_goToPlayer_clicked(); + void on_tool_new_file_clicked(); + void on_tool_new_dir_clicked(); // -- Top Snapshot Buttons void on_tool_snap_newer_clicked(); void on_tool_snap_older_clicked(); diff --git a/lumina-fm/widgets/DirWidget.ui b/lumina-fm/widgets/DirWidget.ui index 42b4a075..a1fdca3d 100644 --- a/lumina-fm/widgets/DirWidget.ui +++ b/lumina-fm/widgets/DirWidget.ui @@ -44,6 +44,32 @@ + + + + Create a new directory + + + New Dir + + + Qt::ToolButtonTextBesideIcon + + + + + + + Create a new file + + + New File + + + Qt::ToolButtonTextBesideIcon + + + diff --git a/lumina-fm/widgets/SlideshowWidget.ui b/lumina-fm/widgets/SlideshowWidget.ui index d262d5ec..cab4c5f9 100644 --- a/lumina-fm/widgets/SlideshowWidget.ui +++ b/lumina-fm/widgets/SlideshowWidget.ui @@ -14,6 +14,18 @@ Form + + 1 + + + 1 + + + 1 + + + 1 + @@ -128,8 +140,8 @@ 0 0 - 350 - 250 + 364 + 264 -- cgit