diff options
Diffstat (limited to 'lumina-fileinfo')
-rw-r--r-- | lumina-fileinfo/MainUI.cpp | 236 | ||||
-rw-r--r-- | lumina-fileinfo/MainUI.h | 55 | ||||
-rw-r--r-- | lumina-fileinfo/MainUI.ui (renamed from lumina-fileinfo/dialog.ui) | 263 | ||||
-rw-r--r-- | lumina-fileinfo/defaults/fileinfo-app.template | 11 | ||||
-rw-r--r-- | lumina-fileinfo/defaults/fileinfo-link.template | 7 | ||||
-rw-r--r-- | lumina-fileinfo/dialog.cpp | 403 | ||||
-rw-r--r-- | lumina-fileinfo/dialog.h | 51 | ||||
-rw-r--r-- | lumina-fileinfo/lumina-fileinfo.pro | 8 | ||||
-rw-r--r-- | lumina-fileinfo/lumina-fileinfo.qrc | 6 | ||||
-rw-r--r-- | lumina-fileinfo/main.cpp | 52 |
10 files changed, 462 insertions, 630 deletions
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 <QFileDialog> +#include <QMessageBox> + +#include <LuminaUtils.h> +#include <LuminaOS.h> + +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; i<ext.length(); i++){ ext[i].prepend("*."); } //turn them into valid filters + QString file = QFileDialog::getOpenFileName(this, tr("Select an icon"), dir ,QString(tr("Images (%1);; All Files (*)")).arg(ext.join(" ")) ); + if(file.isEmpty()){ return; } //cancelled + ui->push_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 <QDialog> + +#include <LuminaXDG.h> + +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/dialog.ui b/lumina-fileinfo/MainUI.ui index 2827127c..89035259 100644 --- a/lumina-fileinfo/dialog.ui +++ b/lumina-fileinfo/MainUI.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> + <class>MainUI</class> + <widget class="QDialog" name="MainUI"> <property name="geometry"> <rect> <x>0</x> @@ -17,7 +17,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>0</number> + <number>1</number> </property> <widget class="QWidget" name="tab_file"> <attribute name="title"> @@ -172,6 +172,16 @@ </property> </widget> </item> + <item row="0" column="1"> + <widget class="QLabel" name="label_file_name"> + <property name="text"> + <string notr="true"/> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> <widget class="QWidget" name="tab_deskedit"> @@ -199,46 +209,19 @@ <item row="3" column="0" alignment="Qt::AlignRight"> <widget class="QLabel" name="lblWorkingDir"> <property name="text"> - <string>Working dir:</string> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QPushButton" name="pbWorkingDir"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/places/folder.png</normalon> - </iconset> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QPushButton" name="pbCommand"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png</normalon> - </iconset> + <string>Working Dir:</string> </property> </widget> </item> <item row="5" column="1"> - <widget class="QCheckBox" name="cbStartupNotification"> + <widget class="QCheckBox" name="check_xdg_startupNotify"> <property name="text"> <string>Use startup notification</string> </property> </widget> </item> <item row="3" column="1"> - <widget class="QLineEdit" name="lWorkingDir"> + <widget class="QLineEdit" name="line_xdg_wdir"> <property name="enabled"> <bool>true</bool> </property> @@ -266,34 +249,10 @@ </widget> </item> <item row="2" column="1"> - <widget class="QLineEdit" name="lCommand"/> - </item> - <item row="4" column="1" alignment="Qt::AlignLeft"> - <widget class="QPushButton" name="pbIcon"> - <property name="maximumSize"> - <size> - <width>275</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png</normalon> - </iconset> - </property> - <property name="iconSize"> - <size> - <width>64</width> - <height>64</height> - </size> - </property> - </widget> + <widget class="QLineEdit" name="line_xdg_command"/> </item> <item row="6" column="1"> - <widget class="QCheckBox" name="cbRunInTerminal"> + <widget class="QCheckBox" name="check_xdg_useTerminal"> <property name="text"> <string>Run in terminal</string> </property> @@ -314,104 +273,136 @@ </widget> </item> <item row="0" column="1" colspan="2"> - <widget class="QLineEdit" name="lName"/> + <widget class="QLineEdit" name="line_xdg_name"/> </item> <item row="1" column="1" colspan="2"> - <widget class="QLineEdit" name="lComment"/> + <widget class="QLineEdit" name="line_xdg_comment"/> </item> - </layout> - </item> - <item> - <widget class="Line" name="line"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pbCancel"> + <item row="2" column="2"> + <widget class="QToolButton" name="tool_xdg_getCommand"> <property name="text"> - <string>Cancel</string> + <string notr="true"/> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png</normalon> + </iconset> </property> </widget> </item> - <item> - <widget class="QPushButton" name="pbApply"> + <item row="3" column="2"> + <widget class="QToolButton" name="tool_xdg_getDir"> + <property name="enabled"> + <bool>true</bool> + </property> <property name="text"> - <string>Apply</string> + <string notr="true"/> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/places/folder.png</normalon> + </iconset> </property> </widget> </item> + <item row="4" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QToolButton" name="push_xdg_getIcon"> + <property name="maximumSize"> + <size> + <width>275</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>No Icon</string> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png</normalon> + </iconset> + </property> + <property name="iconSize"> + <size> + <width>64</width> + <height>64</height> + </size> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> </layout> </widget> </widget> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="push_save"> + <property name="text"> + <string>Save</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="push_close"> + <property name="text"> + <string>Close</string> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> <layoutdefault spacing="6" margin="11"/> <tabstops> - <tabstop>lName</tabstop> - <tabstop>lComment</tabstop> - <tabstop>lCommand</tabstop> - <tabstop>lWorkingDir</tabstop> - <tabstop>pbIcon</tabstop> - <tabstop>cbStartupNotification</tabstop> - <tabstop>cbRunInTerminal</tabstop> - <tabstop>pbCancel</tabstop> - <tabstop>pbApply</tabstop> - <tabstop>pbCommand</tabstop> - <tabstop>pbWorkingDir</tabstop> + <tabstop>line_xdg_name</tabstop> + <tabstop>line_xdg_comment</tabstop> + <tabstop>line_xdg_command</tabstop> + <tabstop>line_xdg_wdir</tabstop> + <tabstop>check_xdg_startupNotify</tabstop> + <tabstop>check_xdg_useTerminal</tabstop> + <tabstop>tool_xdg_getCommand</tabstop> + <tabstop>tool_xdg_getDir</tabstop> </tabstops> <resources/> - <connections> - <connection> - <sender>pbCancel</sender> - <signal>clicked()</signal> - <receiver>Dialog</receiver> - <slot>close()</slot> - <hints> - <hint type="sourcelabel"> - <x>289</x> - <y>286</y> - </hint> - <hint type="destinationlabel"> - <x>274</x> - <y>316</y> - </hint> - </hints> - </connection> - <connection> - <sender>pbApply</sender> - <signal>clicked()</signal> - <receiver>Dialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>375</x> - <y>286</y> - </hint> - <hint type="destinationlabel"> - <x>372</x> - <y>318</y> - </hint> - </hints> - </connection> - </connections> + <connections/> </ui> 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 <QFileDialog> -#include <QRegExp> -#include <QTemporaryFile> -#include <QMessageBox> -#include <QImageReader> -#include "LuminaUtils.h" -#include <LuminaOS.h> - - -//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<QByteArray> fmt = QImageReader::supportedImageFormats(); - bool foundimage=false; - for(int i=0; i<fmt.length(); i++){ - if(info.suffix().toLower() == QString(fmt[i]).toLower()){foundimage=true; break; } - } - if(foundimage){ - ui->label_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 <QDialog> -#include <LuminaXDG.h> - -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/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 @@ -<RCC> - <qresource> - <file>defaults/fileinfo-app.template</file> - <file>defaults/fileinfo-link.template</file> - </qresource> -</RCC> 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 <QDebug> #include <QFile> -#include "dialog.h" +#include "MainUI.h" #include <LuminaUtils.h> #include <LuminaThemes.h> @@ -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] <file>"; + qDebug() << msg.join("\n"); + return 1; + } + - int retCode = a.exec(); - return retCode; }
\ No newline at end of file |