From c168111955fdaac4b546e82138de5e75545cfb07 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 26 Mar 2015 21:54:09 +0100 Subject: put the name lumina-fileinfo --- desktop-editor/desktop-app.template | 11 -- desktop-editor/desktop-editor.pro | 32 ----- desktop-editor/desktop-link.template | 7 - desktop-editor/dialog.cpp | 241 ----------------------------------- desktop-editor/dialog.h | 46 ------- desktop-editor/dialog.ui | 226 -------------------------------- desktop-editor/global.h | 3 - desktop-editor/main.cpp | 20 --- 8 files changed, 586 deletions(-) delete mode 100644 desktop-editor/desktop-app.template delete mode 100644 desktop-editor/desktop-editor.pro delete mode 100644 desktop-editor/desktop-link.template delete mode 100644 desktop-editor/dialog.cpp delete mode 100644 desktop-editor/dialog.h delete mode 100644 desktop-editor/dialog.ui delete mode 100644 desktop-editor/global.h delete mode 100644 desktop-editor/main.cpp (limited to 'desktop-editor') diff --git a/desktop-editor/desktop-app.template b/desktop-editor/desktop-app.template deleted file mode 100644 index 8519d3a1..00000000 --- a/desktop-editor/desktop-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/desktop-editor/desktop-editor.pro b/desktop-editor/desktop-editor.pro deleted file mode 100644 index dc3eadf2..00000000 --- a/desktop-editor/desktop-editor.pro +++ /dev/null @@ -1,32 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2015-02-24T18:52:15 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = desktop-editor -TEMPLATE = app - -isEmpty(PREFIX) { - PREFIX = /usr/local -} - -isEmpty(LIBPREFIX) { - LIBPREFIX = $$PREFIX/lib -} - - -SOURCES += main.cpp\ - dialog.cpp - -HEADERS += dialog.h - -FORMS += dialog.ui - -INCLUDEPATH += $$PREFIX/include - -LIBS += -L$$LIBPREFIX -lLuminaUtils diff --git a/desktop-editor/desktop-link.template b/desktop-editor/desktop-link.template deleted file mode 100644 index 4a0b7830..00000000 --- a/desktop-editor/desktop-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/desktop-editor/dialog.cpp b/desktop-editor/dialog.cpp deleted file mode 100644 index 359257d6..00000000 --- a/desktop-editor/dialog.cpp +++ /dev/null @@ -1,241 +0,0 @@ -#include "dialog.h" -#include "ui_dialog.h" -#include -#include -#include -#include -#include "LuminaUtils.h" -#include - -Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) -{ - ui->setupUi(this); - desktopType="Application"; //default value - - //Setup all the icons using libLumina - this->setWindowIcon( LXDG::findIcon("preferences-desktop-default-applications","") ); - ui->pbWorkingDir->setIcon( LXDG::findIcon("folder","") ); - ui->pbCommand->setIcon( LXDG::findIcon("system-search","") ); -} - - -Dialog::~Dialog() -{ - delete ui; -} - -//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("The application requires inputs: <-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("URL"); //we use the WorkingDir boxes for URL - desktopType="link"; - } -} - - - - -//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 - //TODO: have a config directory to store templates - if (!QFile::exists(input)) { - if (desktopType=="link") { QFile::copy("./desktop-link.template", desktopFileName);} - else { QFile::copy("./desktop-app.template", desktopFileName);} - } - - //use the standard LXDG object and load the desktop file - bool ok = false; - 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(QPixmap(DF.icon)); - } else { - QMessageBox::critical(this, tr("Error"), tr("Problem to read the desktop file called:") + desktopFileName ); - exit(1); - } -} - - -void Dialog::on_pbCommand_clicked() -{ - //the default directory is the user's home directory - QString commandFolder = "~"; - if (!ui->lCommand->text().isEmpty()) commandFolder = ui->lCommand->text().section('/', 0, -2); - if (commandFolder.isEmpty()) commandFolder = "~"; - - 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); - } -} - -//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*=",Qt::CaseInsensitive))) { - QMessageBox msgBox; - msgBox.setText(tr("By modifying this value, you will loose all translated versions")); - msgBox.setInformativeText(tr("The field:") + topic + tr( "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. - origin.replace(QRegExp("\n" + topic + "\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), ""); - } - else return; - } - if (!from.isEmpty()) { - origin.replace(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive),"\n" + topic + "=" + to + "\n"); - } else { - //TODO: check if last char in \n. If not add it - origin.append(topic + "=" + to + "\n"); - } -} - -//we save the changes to the destination file -void Dialog::on_pbApply_clicked() -{ - - QByteArray fileData; - QFile file(desktopFileName); - if (file.open(QFile::ReadWrite)) { - QString from,to; - fileData = file.readAll(); - QString text(fileData); - - 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(text, desktopTypeVal, desktopType, "Type"); - - if (ui->lName->isModified()) { textReplace(text, DF.name, ui->lName->text(), "Name");} - if (ui->lComment->isModified()) { textReplace(text, DF.comment, ui->lComment->text(), "Comment");} - if (ui->lCommand->isModified()) { textReplace(text, DF.exec, ui->lCommand->text(),"Exec");} - if (desktopType=="link") { - //incase of "link" layout WorkingDir is corresponding to the URL - if (ui->lWorkingDir->isModified()) { textReplace(text, DF.url, ui->lWorkingDir->text(),"URL");} - } else { - if (ui->lWorkingDir->isModified()) { textReplace(text, 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(text, from, to,"StartupNotify"); - } - if (ui->cbRunInTerminal->isChecked() != DF.useTerminal) { - if (DF.useTerminal) {from="true"; to="false";} else {from="false"; to="true";} - textReplace(text, from, to,"Terminal"); - } - if (!iconFileName.isEmpty()) { - from=DF.icon; - to=iconFileName; - textReplace(text, from, to,"Icon"); - } - - file.seek(0); - file.write(text.toUtf8()); - - file.resize(file.pos());//remove possible trailing lines - - file.close(); - - //hack required to update the icon on the desktop - //maybe the solution would be to have a QFileSystemWatcher (in AppLauncherPlugin.cpp) - //on files instead of ~/Desktop - QTemporaryFile tempFile ; - tempFile.setAutoRemove(false); - tempFile.open(); - tempFile.close(); - - //TODO: capture errors - QString cmd = "mv"; - cmd = cmd + " " + desktopFileName + " " + tempFile.fileName(); - int ret = LUtils::runCmd(cmd); - - cmd = "mv"; - cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName; - ret = LUtils::runCmd(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; - } -} diff --git a/desktop-editor/dialog.h b/desktop-editor/dialog.h deleted file mode 100644 index e58f0938..00000000 --- a/desktop-editor/dialog.h +++ /dev/null @@ -1,46 +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 desktopFileName ; - QString iconFileName; - QString desktopType; - - void Initialise(QString); - void MissingInputs(); - void LoadDesktopFile(QString); - - ~Dialog(); - -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); - -private: - Ui::Dialog *ui; -}; - -#endif // DIALOG_H diff --git a/desktop-editor/dialog.ui b/desktop-editor/dialog.ui deleted file mode 100644 index 8cca25d4..00000000 --- a/desktop-editor/dialog.ui +++ /dev/null @@ -1,226 +0,0 @@ - - - Dialog - - - - 0 - 0 - 383 - 288 - - - - Desktop Editor - - - - - - - - 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 - - - - 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/desktop-editor/global.h b/desktop-editor/global.h deleted file mode 100644 index f93e2d08..00000000 --- a/desktop-editor/global.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef PREFIX - #define PREFIX QString("/usr/local") -#endif diff --git a/desktop-editor/main.cpp b/desktop-editor/main.cpp deleted file mode 100644 index 39a96321..00000000 --- a/desktop-editor/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "dialog.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - Dialog w; - 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(); - } - a.setApplicationName("Desktop Editor"); - w.show(); - - return a.exec(); -} -- cgit