From d8139ce95ae39cd2b4cf6c7fd08cc6dcb119a485 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 31 Aug 2015 14:22:07 -0400 Subject: Completely overhaul lumina-fileinfo so that it is just a front-end to the XDGDesktop structure now, instead of using the regex's and template files like before. This also makes it easier to update later, since there are more information fields in the XDGDesktop structure than lumina-fileinfo currently handles (TryExec, Actions, ShowIn, etc). --- lumina-fileinfo/MainUI.cpp | 236 ++++++++++++++ lumina-fileinfo/MainUI.h | 55 ++++ lumina-fileinfo/MainUI.ui | 408 +++++++++++++++++++++++ lumina-fileinfo/defaults/fileinfo-app.template | 11 - lumina-fileinfo/defaults/fileinfo-link.template | 7 - lumina-fileinfo/dialog.cpp | 403 ----------------------- lumina-fileinfo/dialog.h | 51 --- lumina-fileinfo/dialog.ui | 417 ------------------------ lumina-fileinfo/lumina-fileinfo.pro | 8 +- lumina-fileinfo/lumina-fileinfo.qrc | 6 - lumina-fileinfo/main.cpp | 52 ++- 11 files changed, 743 insertions(+), 911 deletions(-) create mode 100644 lumina-fileinfo/MainUI.cpp create mode 100644 lumina-fileinfo/MainUI.h create mode 100644 lumina-fileinfo/MainUI.ui delete mode 100644 lumina-fileinfo/defaults/fileinfo-app.template delete mode 100644 lumina-fileinfo/defaults/fileinfo-link.template delete mode 100644 lumina-fileinfo/dialog.cpp delete mode 100644 lumina-fileinfo/dialog.h delete mode 100644 lumina-fileinfo/dialog.ui delete mode 100644 lumina-fileinfo/lumina-fileinfo.qrc diff --git a/lumina-fileinfo/MainUI.cpp b/lumina-fileinfo/MainUI.cpp new file mode 100644 index 00000000..02ee8dfb --- /dev/null +++ b/lumina-fileinfo/MainUI.cpp @@ -0,0 +1,236 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "MainUI.h" +#include "ui_MainUI.h" + +#include +#include + +#include +#include + +LFileInfo INFO = LFileInfo(""); + +MainUI::MainUI() : QDialog(), ui(new Ui::MainUI){ + ui->setupUi(this); //load the designer form + canwrite = false; + UpdateIcons(); //Set all the icons in the dialog + SetupConnections(); +} + +MainUI::~MainUI(){ + +} + +//============= +// PUBLIC +//============= +void MainUI::LoadFile(QString path, QString type){ + INFO = LFileInfo(path); + if(INFO.exists()){ canwrite = INFO.isWritable(); } + else{ + //See if the containing directory can be written + QFileInfo chk(INFO.absolutePath()); + canwrite = (chk.isDir() && chk.isWritable()); + } + if(!INFO.exists() && !type.isEmpty()){ + //Set the proper type flag on the shortcut + if(type=="APP"){ INFO.XDG()->type = XDGDesktop::APP; } + else if(type=="LINK"){ INFO.XDG()->type = XDGDesktop::LINK; } + } + + //First load the general file information + ui->label_file_name->setText( INFO.fileName() ); + ui->label_file_mimetype->setText( INFO.mimetype() ); + if(!INFO.isDir()){ ui->label_file_size->setText( LUtils::BytesToDisplaySize( INFO.size() ) ); } + ui->label_file_owner->setText(INFO.owner()); + ui->label_file_group->setText(INFO.group()); + ui->label_file_created->setText( INFO.created().toString(Qt::SystemLocaleLongDate) ); + ui->label_file_modified->setText( INFO.lastModified().toString(Qt::SystemLocaleLongDate) ); + //Get the file permissions + QString perms; + if(INFO.isReadable() && INFO.isWritable()){ perms = tr("Read/Write"); } + else if(INFO.isReadable()){ perms = tr("Read Only"); } + else if(INFO.isWritable()){ perms = tr("Write Only"); } + else{ perms = tr("No Access"); } + ui->label_file_perms->setText(perms); + //Now the special "type" for the file + QString ftype; + if(INFO.suffix().toLower()=="desktop"){ ftype = tr("XDG Shortcut"); } + else if(INFO.isDir()){ ftype = tr("Directory"); } + else if(INFO.isExecutable()){ ftype = tr("Binary"); } + else{ ftype = INFO.suffix().toUpper(); } + if(INFO.isHidden()){ ftype = QString(tr("Hidden %1")).arg(type); } + ui->label_file_type->setText(ftype); + //Now load the icon for the file + if(INFO.isImage()){ + ui->label_file_icon->setPixmap( QPixmap(INFO.absoluteFilePath()).scaledToHeight(64) ); + }else{ + ui->label_file_icon->setPixmap( LXDG::findIcon( INFO.iconfile(), "unknown").pixmap(QSize(64,64)) ); + } + //Now load the special XDG desktop info + if(INFO.isDesktopFile()){ + + if(INFO.XDG()->type == XDGDesktop::APP){ + ui->line_xdg_command->setText(INFO.XDG()->exec); + ui->line_xdg_wdir->setText(INFO.XDG()->path); + ui->check_xdg_useTerminal->setChecked( INFO.XDG()->useTerminal ); + ui->check_xdg_startupNotify->setChecked( INFO.XDG()->startupNotify ); + }else if(INFO.XDG()->type==XDGDesktop::LINK){ + //Hide the options that are unavailable for links + //Command line (exec) + ui->line_xdg_command->setVisible(false); + ui->tool_xdg_getCommand->setVisible(false); + ui->lblCommand->setVisible(false); + //Options + ui->lblOptions->setVisible(false); + ui->check_xdg_useTerminal->setVisible(false); + ui->check_xdg_startupNotify->setVisible(false); + //Now load the variables for this type of shortcut + ui->lblWorkingDir->setText(tr("URL:")); + ui->line_xdg_wdir->setText( INFO.XDG()->url ); + ui->tool_xdg_getDir->setVisible(false); //the dir selection button + + } + ui->line_xdg_name->setText(INFO.XDG()->name); + ui->line_xdg_comment->setText(INFO.XDG()->comment); + ui->push_xdg_getIcon->setWhatsThis( INFO.XDG()->icon ); + ReloadAppIcon(); + ui->push_save->setVisible(true); + ui->push_save->setEnabled(false); + }else{ + xdgvaluechanged(); //just do the disables here + //Also remove the xdg tab + if(ui->tabWidget->count()>1){ ui->tabWidget->removeTab(1); } + } + //Setup the tab + if(type.isEmpty()){ ui->tabWidget->setCurrentIndex(0); } + else if(ui->tabWidget->count()>1){ ui->tabWidget->setCurrentIndex(1); } + +} + +void MainUI::UpdateIcons(){ + this->setWindowIcon(LXDG::findIcon("document-preview","unknown")); + ui->push_close->setIcon( LXDG::findIcon("dialog-close","") ); + ui->push_save->setIcon( LXDG::findIcon("document-save","") ); + ui->tool_xdg_getCommand->setIcon( LXDG::findIcon("edit-find-project","") ); + ui->tool_xdg_getDir->setIcon( LXDG::findIcon("document-open","") ); +} + +//============== +// PRIVATE +//============== +void MainUI::ReloadAppIcon(){ + ui->push_xdg_getIcon->setIcon( LXDG::findIcon(ui->push_xdg_getIcon->whatsThis(),"") ); +} + +// Initialization procedures +void MainUI::SetupConnections(){ + connect(ui->line_xdg_command, SIGNAL(editingFinished()), this, SLOT(xdgvaluechanged()) ); + connect(ui->line_xdg_comment, SIGNAL(editingFinished()), this, SLOT(xdgvaluechanged()) ); + connect(ui->line_xdg_name, SIGNAL(editingFinished()), this, SLOT(xdgvaluechanged()) ); + connect(ui->line_xdg_wdir, SIGNAL(editingFinished()), this, SLOT(xdgvaluechanged()) ); + connect(ui->check_xdg_useTerminal, SIGNAL(clicked()), this, SLOT(xdgvaluechanged()) ); + connect(ui->check_xdg_startupNotify, SIGNAL(clicked()), this, SLOT(xdgvaluechanged()) ); +} + +//UI Buttons +void MainUI::on_push_close_clicked(){ + if(ui->push_save->isEnabled()){ + //Still have unsaved changes + //TO-DO - prompt for whether to save the changes + + } + this->close(); +} + +void MainUI::on_push_save_clicked(){ + //Save all the xdg values into the structure + if(!INFO.isDesktopFile() || !canwrite){ return; } + XDGDesktop XDG = *INFO.XDG();; + //Now change the structure + XDG.name = ui->line_xdg_name->text(); + XDG.genericName = ui->line_xdg_name->text().toLower(); + XDG.comment = ui->line_xdg_comment->text(); + XDG.icon = ui->push_xdg_getIcon->whatsThis(); + //Now do the type-specific fields + if(XDG.type==XDGDesktop::APP){ + XDG.exec = ui->line_xdg_command->text(); + XDG.tryexec = ui->line_xdg_command->text().section(" ",0,0); //use the first word/binary for the existance check + XDG.path = ui->line_xdg_wdir->text(); //working dir/path + XDG.useTerminal = ui->check_xdg_useTerminal->isChecked(); + XDG.startupNotify = ui->check_xdg_startupNotify->isChecked(); + }else if(XDG.type==XDGDesktop::LINK){ + XDG.url = ui->line_xdg_wdir->text(); //we re-used this field + } + //Clear any info which this utility does not support at the moment + XDG.actionList.clear(); + XDG.actions.clear(); + //Now save the structure to file + bool saved = LXDG::saveDesktopFile( XDG, true); //Try to merge the file/structure as necessary + qDebug() << "File Saved:" << saved; + ui->push_save->setEnabled( !saved ); + if(saved){ + //Re-load the file info + LoadFile(INFO.absoluteFilePath()); + } +} + +void MainUI::on_tool_xdg_getCommand_clicked(QString prev){ + //Find a binary to run + QString dir = prev; //start with the previous attempt (if there was one) + if(dir.isEmpty()){ ui->line_xdg_command->text(); }//then try current selection + if(dir.isEmpty()){ dir = LOS::AppPrefix()+"bin"; } //then open the application binaries directory + QString file = QFileDialog::getOpenFileName(this, tr("Select a binary"), dir ); + if(file.isEmpty()){ return; } //cancelled + if(!LUtils::isValidBinary(file)){ + QMessageBox::warning(this, tr("Error"), tr("Invalid selection: Not a valid executable")); + on_tool_xdg_getCommand_clicked(file); + return; + } + ui->line_xdg_command->setText(file); + xdgvaluechanged(); +} + +void MainUI::on_tool_xdg_getDir_clicked(){ + //Find a directory + QString dir = ui->line_xdg_wdir->text(); + if(dir.isEmpty()){ dir = QDir::homePath(); } + dir = QFileDialog::getExistingDirectory(this, tr("Select a directory"), dir); + if(dir.isEmpty()){ return; } //cancelled + ui->line_xdg_wdir->setText(dir); + xdgvaluechanged(); +} + +void MainUI::on_push_xdg_getIcon_clicked(){ + //Find an image file + QString dir = ui->push_xdg_getIcon->whatsThis(); //then try current selection + if(dir.isEmpty()){ dir = QDir::homePath(); } + //Get the known file extensions + QStringList ext = LUtils::imageExtensions(); + for(int i=0; ipush_xdg_getIcon->setWhatsThis(file); + ReloadAppIcon(); + xdgvaluechanged(); +} + +//XDG Value Changed +void MainUI::xdgvaluechanged(){ + if(INFO.isDesktopFile()){ + ui->push_save->setVisible(true); + //Compare the current UI values to the file values + ui->push_save->setEnabled(canwrite); //assume changed at this point + // TO-DO + + }else{ + ui->push_save->setVisible(false); + ui->push_save->setEnabled(false); + } +} + diff --git a/lumina-fileinfo/MainUI.h b/lumina-fileinfo/MainUI.h new file mode 100644 index 00000000..bc2729fd --- /dev/null +++ b/lumina-fileinfo/MainUI.h @@ -0,0 +1,55 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// Note: Some of this class (particularly parts of the UI), were initially created by: +// William (william-os4y on GitHub: https://github.com/william-os4y) +// March -> April, 2015 +// This utility was re-written by Ken Moore on August 31, 2015 +// Primarily to align the utility with the LWinInfo & XDGDesktop classes +//=========================================== +#ifndef _LUMINA_FILE_INFO_MAIN_UI_H +#define _LUMINA_FILE_INFO_MAIN_UI_H + +#include + +#include + +namespace Ui{ + class MainUI; +}; + +class MainUI : public QDialog{ + Q_OBJECT +public: + MainUI(); + ~MainUI(); + + void LoadFile(QString path, QString type=""); //type=[APP, LINK] + +public slots: + void UpdateIcons(); + +private: + Ui::MainUI *ui; + bool canwrite; + void ReloadAppIcon(); + +private slots: + //Initialization functions + void SetupConnections(); + + //UI Buttons + void on_push_close_clicked(); + void on_push_save_clicked(); + void on_tool_xdg_getCommand_clicked(QString prev = ""); + void on_tool_xdg_getDir_clicked(); + void on_push_xdg_getIcon_clicked(); + + //XDG Value Changed + void xdgvaluechanged(); +}; + +#endif diff --git a/lumina-fileinfo/MainUI.ui b/lumina-fileinfo/MainUI.ui new file mode 100644 index 00000000..89035259 --- /dev/null +++ b/lumina-fileinfo/MainUI.ui @@ -0,0 +1,408 @@ + + + MainUI + + + + 0 + 0 + 349 + 327 + + + + File Information + + + + + + 1 + + + + File Properties + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + icon + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Owner: + + + + + + + + + + + + + + Group: + + + + + + + + + + + + + + Permissions: + + + + + + + Qt::Horizontal + + + + + + + Created: + + + + + + + Note: The time a file was created might be more recent than the time modified if the file permissions were changed recently. + + + + + + + + + + Last Modified: + + + + + + + Type: + + + + + + + MimeType: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + File Size: + + + + + + + + + + + + + + + + + true + + + + + + + + Edit Shortcut + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Working Dir: + + + + + + + Use startup notification + + + + + + + true + + + + + + + Icon: + + + + + + + Command: + + + + + + + Comment: + + + + + + + + + + Run in terminal + + + + + + + Name: + + + + + + + Options + + + + + + + + + + + + + + + + + ../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png + + + + + + + + true + + + + + + + ../../../../usr/local/share/icons/gnome/32x32/places/folder.png + + + + + + + + + + + 275 + 16777215 + + + + No Icon + + + + ../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png + + + + + 64 + 64 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save + + + + + + + Close + + + + + + + + + + line_xdg_name + line_xdg_comment + line_xdg_command + line_xdg_wdir + check_xdg_startupNotify + check_xdg_useTerminal + tool_xdg_getCommand + tool_xdg_getDir + + + + diff --git a/lumina-fileinfo/defaults/fileinfo-app.template b/lumina-fileinfo/defaults/fileinfo-app.template deleted file mode 100644 index 8519d3a1..00000000 --- a/lumina-fileinfo/defaults/fileinfo-app.template +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Version=1.0 -Encoding=UTF-8 -Name=Name -Exec=Command -Icon=system-help.png -StartupNotify=false -Terminal=false -Type=Application -Categories=Application -Comment=Comment diff --git a/lumina-fileinfo/defaults/fileinfo-link.template b/lumina-fileinfo/defaults/fileinfo-link.template deleted file mode 100644 index 4a0b7830..00000000 --- a/lumina-fileinfo/defaults/fileinfo-link.template +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Version=1.0 -Encoding=UTF-8 -Name=Name -Icon=system-help.png -Type=Link -Comment=Comment diff --git a/lumina-fileinfo/dialog.cpp b/lumina-fileinfo/dialog.cpp deleted file mode 100644 index fe6e69c3..00000000 --- a/lumina-fileinfo/dialog.cpp +++ /dev/null @@ -1,403 +0,0 @@ -#include "dialog.h" -#include "ui_dialog.h" -#include -#include -#include -#include -#include -#include "LuminaUtils.h" -#include - - -//this function is just like a regexp. -//we just change the required lines and we don't touch to the rest of the file and copy it back. -void Dialog::textReplace(QString &origin, QString from, QString to, QString topic) -{ - if (origin.contains(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive))) { - origin.replace(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive),"\n" + topic + "=" + to + "\n"); - } else { - origin.append(topic + "=" + to + "\n"); - } -} - -//get the template from the user home directory or from the qrc files -void Dialog::copyTemplate(QString templateType) -{ - if ((templateType == "-link") or (templateType == "-app")) { - if (QFile::exists(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template")) { - //We take the template from homedir - QFile::copy(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template", desktopFileName); - } else { - //last possibility is to use the qrc template. - //But based on the initialisation, this should never occurs - QFile::copy(":defaults/fileinfo" + templateType + ".template", desktopFileName); - } - } else { - //error message for developpers - qDebug() << "copyTemplate only accept '-link' or '-app' as parameter"; - } -} - - - - -Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) -{ - ui->setupUi(this); - desktopType="Application"; //default value - - //Setup all the icons using libLumina - setupIcons(); - - //we copy qrc templates in the home dir of the user. - //this allow the user to adapt those template to is own whishes - QString templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-link.template"; - if (!QFile::exists(templateFile)) { - QFile::copy(":defaults/fileinfo-link.template", templateFile); - QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); - } - templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-app.template"; - if (!QFile::exists(templateFile)) { - QFile::copy(":defaults/fileinfo-app.template", templateFile); - QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); - } -} - - -Dialog::~Dialog() -{ - delete ui; -} - -void Dialog::setupIcons(){ - this->setWindowIcon( LXDG::findIcon("unknown","") ); - ui->pbWorkingDir->setIcon( LXDG::findIcon("folder","") ); - ui->pbCommand->setIcon( LXDG::findIcon("system-search","") ); -} - -//Inform the user that required input parameters are missing -void Dialog::MissingInputs() -{ - qDebug() << "We cannot continue without a desktop file !!!"; - QMessageBox::critical(this, tr("Error"), tr("Lumina-fileinfo requires inputs:")+"\n"+QString(tr("Example: \"%1\"")).arg("lumina-fileinfo <-application>|<-link> desktopfile") ); - exit(1); -} - - -//Initialise the layout of the screen. -void Dialog::Initialise(QString param) -{ - //in case of "link", several objects are no required - if (param.startsWith("-link")) { - ui->cbRunInTerminal->setVisible(false); - ui->cbStartupNotification->setVisible(false); - ui->lCommand->setVisible(false); - ui->pbCommand->setVisible(false); - ui->lblCommand->setVisible(false); - ui->lblOptions->setVisible(false); - ui->lblWorkingDir->setText(tr("URL")); //we use the WorkingDir boxes for URL - desktopType="link"; - } - if (param.startsWith("-app")) { - ui->cbRunInTerminal->setVisible(true); - ui->cbStartupNotification->setVisible(true); - ui->lCommand->setVisible(true); - ui->pbCommand->setVisible(true); - ui->lblCommand->setVisible(true); - ui->lblOptions->setVisible(true); - ui->lblWorkingDir->setText(tr("Working dir")); - desktopType="app"; - } -} - -//load the desktop file or the required template -void Dialog::LoadDesktopFile(QString input) -{ - //if we have "-" as 1st char, it means that this is not a desktop file, but a parameter - desktopFileName = input; - if (input.startsWith("-")) { - QMessageBox::critical(this,tr("Error"),tr("The filename cannot start with a \"-\".")); - exit(1); - } - //if proposed file does not exist, than we will create one based on the templates - QFileInfo info(desktopFileName); - if ((info.size() == 0) && (desktopFileName.endsWith(".desktop"))) { - QFile::remove(desktopFileName); //for the copy, we need to remove it - if (desktopType=="link") { - copyTemplate("-link"); - } else { - copyTemplate("-app"); - } - } - this->setWindowTitle(desktopFileName.section("/",-1)); - ui->tabWidget->setCurrentIndex(0); //always start on the file info tab - //Now load the file info and put it into the UI - QString mime = LXDG::findAppMimeForFile(desktopFileName); - QList fmt = QImageReader::supportedImageFormats(); - bool foundimage=false; - for(int i=0; ilabel_file_icon->setPixmap( QPixmap(desktopFileName).scaledToHeight(64) ); - }else{ - ui->label_file_icon->setPixmap( LXDG::findMimeIcon(mime).pixmap(QSize(64,64)) ); - } - ui->label_file_mimetype->setText(mime); - QString type; - if(desktopFileName.endsWith(".desktop")){ type = tr("XDG Shortcut"); } - else if(info.isDir()){ - type = tr("Directory"); - ui->label_file_mimetype->setText("inode/directory"); - ui->label_file_icon->setPixmap( LXDG::findIcon("folder","").pixmap(QSize(64,64)) ); - }else if(info.isExecutable()){ type = tr("Binary"); } - else{ type = info.suffix().toUpper(); } - if(info.isHidden()){ type = QString(tr("Hidden %1")).arg(type); } - ui->label_file_type->setText(type); - //Calculate the size of the file/dir - QString sz; - if(!info.isDir()){ - sz = LUtils::BytesToDisplaySize(info.size()); - } - // TO-DO calculate the total size of all files within this directory (in a background thread) - ui->label_file_size->setText( sz ); - ui->label_file_owner->setText(info.owner()); - ui->label_file_group->setText(info.group()); - QString perms; - if(info.isReadable() && info.isWritable()){ perms = tr("Read/Write"); } - else if(info.isReadable()){ perms = tr("Read Only"); } - else if(info.isWritable()){ perms = tr("Write Only"); } - else{ perms = tr("No Access"); } - ui->label_file_perms->setText(perms); - ui->label_file_created->setText( info.created().toString(Qt::SystemLocaleLongDate) ); - ui->label_file_modified->setText( info.lastModified().toString(Qt::SystemLocaleLongDate) ); - - //use the standard LXDG object and load the desktop file - bool ok = false; - if(desktopFileName.endsWith(".desktop")){ - DF = LXDG::loadDesktopFile(desktopFileName, ok); - } - if( ok ) { - if ((DF.type == XDGDesktop::LINK) && (desktopType!="link" )) { - //we open a desktop type "link" but it was not mentionned by parameters - Dialog::Initialise("-link"); - } - ui->lName->setText(DF.name); - ui->lComment->setText(DF.comment); - ui->lCommand->setText(DF.exec); - //in case of "link" desktop, we populate the correct content in lWorkingDir - if (desktopType=="link") { - ui->lWorkingDir->setText(DF.url); - } else { - ui->lWorkingDir->setText(DF.path); - } - if (DF.startupNotify) ui->cbStartupNotification->setChecked(true); else ui->cbStartupNotification->setChecked(false); - if (DF.useTerminal) ui->cbRunInTerminal->setChecked(true); else ui->cbRunInTerminal->setChecked(false); - iconFileName=""; - ui->pbIcon->setIcon(LXDG::findIcon(DF.icon,"")); - if(!info.isWritable()){ ui->tab_deskedit->setEnabled(false); } - } else { - ui->tabWidget->removeTab(1); - return; - } - - //we load the file in memory and will adapt it before saving it to disk - QFile file(desktopFileName); - inMemoryFile=""; - if (file.open(QFile::ReadOnly)) { - QTextStream fileData(&file); - inMemoryFile = fileData.readAll(); - file.close(); - //perform some validation checks - //this will allow checks improvements without compilation of the file - if ((inMemoryFile.contains(QRegExp(".*\\[Desktop Entry\\].*\n"))) && - (inMemoryFile.contains(QRegExp("\n\\s*Type\\s*=.*\n"))) && - (inMemoryFile.contains(QRegExp("\n\\s*Name\\s*=.*\n")))) { - //qDebug() << "sounds a good file"; - } else { - //qDebug() << "wrong file!!!!"; - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Question); - msgBox.setText(tr("There are some issues with this file !!!!")); - msgBox.setInformativeText(tr("Either you correct this file your self with an editor, or you start from scratch using the link or app template.\nPlease note that this process will update the file called:") + desktopFileName); - QPushButton *linkButton = msgBox.addButton("Link",QMessageBox::AcceptRole); - QPushButton *appButton = msgBox.addButton("App",QMessageBox::ResetRole); - QPushButton *cancelButton = msgBox.addButton("Cancel",QMessageBox::NoRole); - msgBox.exec(); - if (msgBox.clickedButton() == linkButton) { - QFile::remove(desktopFileName); - copyTemplate("-link"); - Initialise("-link"); - LoadDesktopFile(desktopFileName); - } - if (msgBox.clickedButton() == appButton) { - QFile::remove(desktopFileName); - copyTemplate("-app"); - Initialise("-app"); - LoadDesktopFile(desktopFileName); - } - if (msgBox.clickedButton() == cancelButton) { - //we stop here - exit(0); - } - } - } -} - - -void Dialog::on_pbCommand_clicked() -{ - //the default directory is the user's home directory - QString commandFolder = QDir::homePath(); - if (!ui->lCommand->text().isEmpty()) commandFolder = ui->lCommand->text().section('/', 0, -2); - if (commandFolder.isEmpty()) commandFolder = QDir::homePath(); - - QString fileName = QFileDialog::getOpenFileName(this, - tr("Open command"), commandFolder, tr("All Files (*)")); - if (!fileName.isEmpty()) { - ui->lCommand->setText(fileName); - ui->lCommand->setModified(true); - } -} - - -void Dialog::on_pbWorkingDir_clicked() -{ - //the default directory is / - QString workingDir = "/"; - if (ui->lWorkingDir->text().isEmpty()) workingDir = "/"; - else workingDir = ui->lWorkingDir->text(); - QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; - QString directory = QFileDialog::getExistingDirectory(this, - tr("Working Directory"), - workingDir, - options); - if (!directory.isEmpty()) { - ui->lWorkingDir->setText(directory); - ui->lWorkingDir->setModified(true); - } -} - -//we save the changes to the destination file -void Dialog::on_pbApply_clicked() -{ - QString from,to; - QString desktopTypeVal="Application"; - if (DF.type == XDGDesktop::APP) { desktopTypeVal="Application"; } - else if (DF.type == XDGDesktop::LINK) { desktopTypeVal="Link"; } - else if (DF.type == XDGDesktop::DIR) { desktopTypeVal="Dir"; } - textReplace(inMemoryFile, desktopTypeVal, desktopType, "Type"); - - if (ui->lName->isModified()) { textReplace(inMemoryFile, DF.name, ui->lName->text(), "Name");} - if (ui->lComment->isModified()) { textReplace(inMemoryFile, DF.comment, ui->lComment->text(), "Comment");} - if (ui->lCommand->isModified()) { textReplace(inMemoryFile, DF.exec, ui->lCommand->text(),"Exec");} - if (desktopType=="link") { - //incase of "link" layout WorkingDir is corresponding to the URL - if (ui->lWorkingDir->isModified()) { textReplace(inMemoryFile, DF.url, ui->lWorkingDir->text(),"URL");} - } else { - if (ui->lWorkingDir->isModified()) { textReplace(inMemoryFile, DF.path, ui->lWorkingDir->text(),"Path");} - } - if (ui->cbStartupNotification->isChecked() != DF.startupNotify) { - if (DF.startupNotify) {from="true"; to="false";} else {from="false"; to="true";} - textReplace(inMemoryFile, from, to,"StartupNotify"); - } - if (ui->cbRunInTerminal->isChecked() != DF.useTerminal) { - if (DF.useTerminal) {from="true"; to="false";} else {from="false"; to="true";} - textReplace(inMemoryFile, from, to,"Terminal"); - } - if (!iconFileName.isEmpty()) { - from=DF.icon; - to=iconFileName; - textReplace(inMemoryFile, from, to,"Icon"); - } - - QFile file(desktopFileName); - if (file.open(QFile::ReadWrite)) { - file.seek(0); - file.write(inMemoryFile.toUtf8()); - - file.resize(file.pos());//remove possible trailing lines - - file.close(); - } else { - //problem to write to the disk - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to write the adapted desktop file to the disk. Can you re-try the modification after solving the issue with the disk ?")); - } - - //hack required to update the icon on the desktop - QTemporaryFile tempFile ; - tempFile.setAutoRemove(false); - tempFile.setFileTemplate("/tmp/lumina-XXXXXX"); - tempFile.open(); - tempFile.close(); - - QString cmd = "mv"; - cmd = cmd + " " + desktopFileName + " " + tempFile.fileName(); - int ret = LUtils::runCmd(cmd); - if (ret !=0 ) { - qDebug() << "Problem to execute:" << cmd; - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); - } - - cmd = "mv"; - cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName; - ret = LUtils::runCmd(cmd); - if (ret !=0 ) { - qDebug() << "Problem to execute:" << cmd; - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); - } -} - - -void Dialog::on_pbIcon_clicked() -{ - //the default directory is local/share/icons - QString iconFolder = LOS::AppPrefix()+"/share/icons"; - if (!iconFileName.isEmpty()) iconFolder = iconFileName.section('/', 0, -2); - else if (!DF.icon.isEmpty()) iconFolder = DF.icon.section('/', 0, -2); - if (iconFolder.isEmpty()) iconFolder = LOS::AppPrefix()+"/share/icons"; - - QString fileName = QFileDialog::getOpenFileName(this, - tr("Open command"), iconFolder, tr("Image Files (*.png *.jpg *.bmp)")); - if (!fileName.isEmpty()) { - ui->pbIcon->setIcon(QPixmap(fileName)); - iconFileName=fileName; - } -} - -void Dialog::on_lName_textChanged(QString text) -{ - if (text != DF.name && inMemoryFile.contains(QRegExp("\nName\\[\\S+\\]\\s*=",Qt::CaseInsensitive))) { - QMessageBox msgBox; - msgBox.setText(tr("By modifying this value, you will loose all translated versions")); - msgBox.setInformativeText(tr("The field: Name is translated in several other languages. If you want to continue, you will loose all translated versions")); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - int answer = msgBox.exec(); - if (answer==QMessageBox::Ok) { - //remove all translated versions. The lang cannot be null, but the value can be. - inMemoryFile.replace(QRegExp("\nName\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), ""); - } else { - ui->lName->setText(DF.name); - } - } -} - -void Dialog::on_lComment_textChanged(QString text) -{ - if (text != DF.name && inMemoryFile.contains(QRegExp("\nComment\\[\\S+\\]\\s*=",Qt::CaseInsensitive))) { - QMessageBox msgBox; - msgBox.setText(tr("By modifying this value, you will loose all translated versions")); - msgBox.setInformativeText(tr("The field: Comment is translated in several other languages. If you want to continue, you will loose all translated versions")); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - int answer = msgBox.exec(); - if (answer==QMessageBox::Ok) { - //remove all translated versions. The lang cannot be null, but the value can be. - inMemoryFile.replace(QRegExp("\nComment\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), ""); - } else { - ui->lName->setText(DF.comment); - } - } -} - diff --git a/lumina-fileinfo/dialog.h b/lumina-fileinfo/dialog.h deleted file mode 100644 index 785cb52e..00000000 --- a/lumina-fileinfo/dialog.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef DIALOG_H -#define DIALOG_H - -#include -#include - -namespace Ui { -class Dialog; -} - -class Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit Dialog(QWidget *parent = 0); - - XDGDesktop DF ; - QString inMemoryFile; - - QString desktopFileName ; - QString iconFileName; - QString desktopType; - - void Initialise(QString); - void MissingInputs(); - void LoadDesktopFile(QString); - - ~Dialog(); - -public slots: - void setupIcons(); - -private slots: - - void on_pbCommand_clicked(); - void on_pbWorkingDir_clicked(); - void on_pbApply_clicked(); - void on_pbIcon_clicked(); - - void textReplace(QString &origin, QString from, QString to, QString topic); - void copyTemplate(QString templateType); - - void on_lName_textChanged(QString text); - void on_lComment_textChanged(QString text); - -private: - Ui::Dialog *ui; -}; - -#endif // DIALOG_H diff --git a/lumina-fileinfo/dialog.ui b/lumina-fileinfo/dialog.ui deleted file mode 100644 index 2827127c..00000000 --- a/lumina-fileinfo/dialog.ui +++ /dev/null @@ -1,417 +0,0 @@ - - - Dialog - - - - 0 - 0 - 349 - 327 - - - - File Information - - - - - - 0 - - - - File Properties - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - icon - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - Owner: - - - - - - - - - - - - - - Group: - - - - - - - - - - - - - - Permissions: - - - - - - - Qt::Horizontal - - - - - - - Created: - - - - - - - Note: The time a file was created might be more recent than the time modified if the file permissions were changed recently. - - - - - - - - - - Last Modified: - - - - - - - Type: - - - - - - - MimeType: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - File Size: - - - - - - - - - - - - - - - Edit Shortcut - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - Working dir: - - - - - - - true - - - - - - - ../../../../usr/local/share/icons/gnome/32x32/places/folder.png - - - - - - - - - - - - ../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png - - - - - - - - Use startup notification - - - - - - - true - - - - - - - Icon: - - - - - - - Command: - - - - - - - Comment: - - - - - - - - - - - 275 - 16777215 - - - - - - - - ../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png - - - - - 64 - 64 - - - - - - - - Run in terminal - - - - - - - Name: - - - - - - - Options - - - - - - - - - - - - - - - Qt::Horizontal - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Cancel - - - - - - - Apply - - - - - - - - - - - - - - lName - lComment - lCommand - lWorkingDir - pbIcon - cbStartupNotification - cbRunInTerminal - pbCancel - pbApply - pbCommand - pbWorkingDir - - - - - pbCancel - clicked() - Dialog - close() - - - 289 - 286 - - - 274 - 316 - - - - - pbApply - clicked() - Dialog - accept() - - - 375 - 286 - - - 372 - 318 - - - - - diff --git a/lumina-fileinfo/lumina-fileinfo.pro b/lumina-fileinfo/lumina-fileinfo.pro index 5cab34c9..5342a7ef 100644 --- a/lumina-fileinfo/lumina-fileinfo.pro +++ b/lumina-fileinfo/lumina-fileinfo.pro @@ -16,13 +16,13 @@ isEmpty(LIBPREFIX) { SOURCES += main.cpp\ - dialog.cpp + MainUI.cpp -HEADERS += dialog.h +HEADERS += MainUI.h -FORMS += dialog.ui +FORMS += MainUI.ui -RESOURCES+= lumina-fileinfo.qrc +#RESOURCES+= lumina-fileinfo.qrc INCLUDEPATH += ../libLumina $$PREFIX/include diff --git a/lumina-fileinfo/lumina-fileinfo.qrc b/lumina-fileinfo/lumina-fileinfo.qrc deleted file mode 100644 index 4667589a..00000000 --- a/lumina-fileinfo/lumina-fileinfo.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - defaults/fileinfo-app.template - defaults/fileinfo-link.template - - diff --git a/lumina-fileinfo/main.cpp b/lumina-fileinfo/main.cpp index 1028bbde..f8ba3620 100644 --- a/lumina-fileinfo/main.cpp +++ b/lumina-fileinfo/main.cpp @@ -3,7 +3,7 @@ #include #include -#include "dialog.h" +#include "MainUI.h" #include #include @@ -14,18 +14,46 @@ int main(int argc, char ** argv) LUtils::LoadTranslation(&a, "lumina-fileinfo"); LuminaThemeEngine theme(&a); - Dialog w; - QObject::connect(&theme, SIGNAL(updateIcons()), &w, SLOT(setupIcons()) ); + + //Read the input variables + QString path = ""; + QString flag = ""; if (argc==2) { - w.LoadDesktopFile(QString(argv[1]).simplified()); - } else if (argc==3) { - w.Initialise(QString(argv[1]).simplified()); - w.LoadDesktopFile(QString(argv[2]).simplified()); - } else { - w.MissingInputs(); + path = QString::fromLocal8Bit(argv[1]); + }else if (argc==3) { + flag = QString::fromLocal8Bit(argv[1]); + path = QString::fromLocal8Bit(argv[2]); + } + //Check the input variables + // - path + if(!path.isEmpty()){ path = LUtils::PathToAbsolute(path); } + // - flag + if(!flag.isEmpty()){ + if(flag=="-application"){ + flag = "APP"; //for internal use + }else if(flag=="-link"){ + flag = "LINK"; //for internal use + }else{ + //Invalid flag - clear the path as well + path.clear(); + } } - w.show(); + if(!path.isEmpty()){ + //if(!QFile::exists(path)){ LUtils::writeFile(path,QStringList()); } //create an empty file + MainUI w; + QObject::connect(&theme, SIGNAL(updateIcons()), &w, SLOT(UpdateIcons()) ); + w.LoadFile(path, flag); + w.show(); + int retCode = a.exec(); + return retCode; + }else{ + //Show an error text and exit + QStringList msg; + msg << "ERROR: Invalid input arguments"; + msg << "Usage: \"lumina-fileinfo [-application | -link] "; + qDebug() << msg.join("\n"); + return 1; + } + - int retCode = a.exec(); - return retCode; } \ No newline at end of file -- cgit