diff --git a/data/i18n/conmsgs.ts b/data/i18n/conmsgs.ts index 5ea24e5..7a41398 100644 --- a/data/i18n/conmsgs.ts +++ b/data/i18n/conmsgs.ts @@ -4,32 +4,35 @@ Messages - + __context_verbosity_err__ - + __context_printpass_err__ - + __context_badinvoke_wrn__ - + + + + __context_descfile_wrn%1%2__ - + __context_nodesktop_err__ - + __context_wordexp_wrn__ @@ -132,13 +135,13 @@ - + __enter_pass__ - - + + __launch__ @@ -216,12 +219,12 @@ - + __select_app__ - + __app_selected__ diff --git a/hmtsu.pro b/hmtsu.pro index 68dc447..4c5526e 100644 --- a/hmtsu.pro +++ b/hmtsu.pro @@ -10,7 +10,7 @@ # along with this program. If not, see . # Harmattan boosting through applauncherd daemon requires qdeclarative-boostable -# MNotification and MGConfItem uses meegotouch +# MNotification, MDesktopEntry and MGConfItem uses meegotouch CONFIG += qdeclarative-boostable meegotouch LIBS += -lcrypt -lutil -lX11 @@ -23,7 +23,6 @@ SOURCES += src/main.cpp \ src/hout.cpp \ src/iconprovider.cpp \ src/pswtools.cpp \ - src/desktoptools.cpp \ src/desktopmodel.cpp \ src/usersmodel.cpp \ src/modesmodel.cpp @@ -37,7 +36,6 @@ HEADERS += src/context.h \ src/hout.h \ src/iconprovider.h \ src/pswtools.h \ - src/desktoptools.h \ src/desktopmodel.h \ src/modesmodel.h \ src/usersmodel.h diff --git a/src/common.h b/src/common.h index 7f2e12a..712d14a 100644 --- a/src/common.h +++ b/src/common.h @@ -14,7 +14,7 @@ #ifndef COMMON_H #define COMMON_H -#define HMTSU_VERSION_STRING "v 0.2.0" +#define HMTSU_VERSION_STRING "v 0.2.1" #define HMTSU_COPYRIGHT_STRING "2013 Lcferrum" #define NORMAL_EXIT_CODE 0 diff --git a/src/context.cpp b/src/context.cpp index 65a6aba..b76b365 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -19,10 +19,12 @@ #include #include #include +#include #include #include #include #include +#include "iconprovider.h" #include "context.h" #include "common.h" #include "pswtools.h" @@ -62,7 +64,7 @@ Context::Context(int argc, char **argv): int opt=0; bool use_desktop_file=false; - DesktopFile CurDesktopFile; + QScopedPointer CurDesktopFile(NULL); winsize argp; if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &argp)) { @@ -96,8 +98,8 @@ Context::Context(int argc, char **argv): break; case 'm': if (!access(optarg, R_OK)) { - CurDesktopFile.Open(optarg); - if (LoadValueFromDesktop(CurDesktopFile, "Comment", true, text)) message=ctx_msg_FULL; + CurDesktopFile.reset(new MDesktopEntry(optarg)); + if (LoadCommentFromDesktop(CurDesktopFile.data(), text)) message=ctx_msg_FULL; } else { text=QString::fromLocal8Bit(optarg); message=ctx_msg_FULL; @@ -108,8 +110,8 @@ Context::Context(int argc, char **argv): break; case 'D': if (!access(optarg, R_OK)) { - CurDesktopFile.Open(optarg); - if (LoadValueFromDesktop(CurDesktopFile, "Name", true, text)) message=ctx_msg_DESC; + CurDesktopFile.reset(new MDesktopEntry(optarg)); + if (LoadNameFromDesktop(CurDesktopFile.data(), text)) message=ctx_msg_DESC; } else { text=QString::fromLocal8Bit(optarg); message=ctx_msg_DESC; @@ -142,10 +144,10 @@ Context::Context(int argc, char **argv): } if (use_desktop_file) { - if (CurDesktopFile.IfOpened()) { + if (CurDesktopFile) { QString cmdline; - LoadValueFromDesktop(CurDesktopFile, "Icon", true, icon); - if (LoadExecFromDesktop(CurDesktopFile, cmdline, splash, splash_lscape)) SetCommand(cmdline); //Sets appropriate action (ctx_act_CONTINUE/ctx_act_ASK_FOR_MORE) internally + LoadIconFromDesktop(CurDesktopFile.data(), icon); + if (LoadExecFromDesktop(CurDesktopFile.data(), cmdline, splash, splash_lscape)) SetCommand(cmdline); //Sets appropriate action (ctx_act_CONTINUE/ctx_act_ASK_FOR_MORE) internally } else { action=ctx_act_ASK_FOR_MORE; Intercom->AddError(QCoreApplication::translate("Messages", "__context_nodesktop_err__")); @@ -254,20 +256,44 @@ void Context::SetPreserveEnv(bool flag) kpp_env=flag; } -bool Context::LoadValueFromDesktop(const DesktopFile &CurDesktopFile, const QString &key, bool locval, QString &value) +bool Context::LoadNameFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value) { - if (CurDesktopFile.DesktopKeyValue(key, locval, value)) + if (CurDesktopFile->isValid()) { + value=CurDesktopFile->name(); return true; - else { - Intercom->AddWarning(QCoreApplication::translate("Messages", "__context_descfile_wrn%1%2__").arg(key, CurDesktopFile.Path())); + } else { + Intercom->AddWarning(QCoreApplication::translate("Messages", "__context_descfile_wrn%1%2__").arg("Name", CurDesktopFile->fileName())); + return false; + } +} + +bool Context::LoadCommentFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value) +{ + if (CurDesktopFile->isValid()) { + value=CurDesktopFile->comment(); + return true; + } else { + Intercom->AddWarning(QCoreApplication::translate("Messages", "__context_descfile_wrn%1%2__").arg("Comment", CurDesktopFile->fileName())); + return false; + } +} + +bool Context::LoadIconFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value) +{ + if (CurDesktopFile->isValid()) { + value=CurDesktopFile->icon(); + return true; + } else { + Intercom->AddWarning(QCoreApplication::translate("Messages", "__context_descfile_wrn%1%2__").arg("Icon", CurDesktopFile->fileName())); return false; } } -bool Context::LoadExecFromDesktop(const DesktopFile &CurDesktopFile, QString &cmdline, QString &S, QString &L) +bool Context::LoadExecFromDesktop(const MDesktopEntry *CurDesktopFile, QString &cmdline, QString &S, QString &L) { - QString exec; - if (LoadValueFromDesktop(CurDesktopFile, "Exec", false, exec)) { + if (CurDesktopFile->isValid()) { + QString exec=CurDesktopFile->exec(); + exec.replace(QRegExp("([^%])%[A-Za-z]"), "\\1"); if (exec.startsWith("invoker")||exec.startsWith("/usr/bin/invoker")) { @@ -313,19 +339,21 @@ bool Context::LoadExecFromDesktop(const DesktopFile &CurDesktopFile, QString &cm } return true; - } else + } else { + Intercom->AddWarning(QCoreApplication::translate("Messages", "__context_descfile_wrn%1%2__").arg("Exec", CurDesktopFile->fileName())); return false; + } } QString Context::ForceDesktop(const QString &path) { - DesktopFile GuiApp(path); + MDesktopEntry GuiApp(path); QString cmdline; - if (LoadValueFromDesktop(GuiApp, "Name", true, text)) message=ctx_msg_DESC; + if (LoadNameFromDesktop(&GuiApp, text)) message=ctx_msg_DESC; else message=ctx_msg_CMD; - if (!LoadValueFromDesktop(GuiApp, "Icon", true, icon)) + if (!LoadIconFromDesktop(&GuiApp, icon)) icon=""; - if (!LoadExecFromDesktop(GuiApp, cmdline, splash, splash_lscape)) { + if (!LoadExecFromDesktop(&GuiApp, cmdline, splash, splash_lscape)) { splash=""; splash_lscape=""; } @@ -339,7 +367,7 @@ int Context::GetVerboseLevel() QString Context::GetIcon() { - return DesktopFile::DesktopIconPath(icon); + return IconProvider::ConvertPath(icon); } QString Context::GetRootName() diff --git a/src/context.h b/src/context.h index 6f95c89..3e88b55 100644 --- a/src/context.h +++ b/src/context.h @@ -17,9 +17,9 @@ #include #include #include +#include #include "runtools.h" #include "runmodes.h" -#include "desktoptools.h" #include "commhandler.h" class Context: public QObject, protected IntercomHandler { @@ -41,8 +41,10 @@ class Context: public QObject, protected IntercomHandler { QString splash_lscape; QString icon; QStringList command; - bool LoadValueFromDesktop(const DesktopFile &CurDesktopFile, const QString &key, bool locval, QString &value); - bool LoadExecFromDesktop(const DesktopFile &CurDesktopFile, QString &cmdline, QString &S, QString &L); + bool LoadNameFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value); //Warning: CurDesktopFile can't be NULL! + bool LoadCommentFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value); //Warning: CurDesktopFile can't be NULL! + bool LoadIconFromDesktop(const MDesktopEntry *CurDesktopFile, QString &value); //Warning: CurDesktopFile can't be NULL! + bool LoadExecFromDesktop(const MDesktopEntry *CurDesktopFile, QString &cmdline, QString &S, QString &L); //Warning: CurDesktopFile can't be NULL! public: Context(int argc, char **argv); bool IfExit(); diff --git a/src/desktopmodel.cpp b/src/desktopmodel.cpp index 481ebe0..7854e61 100644 --- a/src/desktopmodel.cpp +++ b/src/desktopmodel.cpp @@ -14,7 +14,8 @@ #include #include #include -#include "desktoptools.h" +#include +#include "iconprovider.h" #include "desktopmodel.h" #define THREAD_TIMEOUT 10000 //10 seconds @@ -72,7 +73,7 @@ bool DesktopModel::PopulateList() void DesktopModel::ReceiveEntry(QString name, QString icon_path, QString full_path) { - //DesktopDescription new_item(name, DesktopFile::DesktopIconPath(icon_path), full_path); + //DesktopDescription new_item(name, IconProvider::ConvertPath(icon_path), full_path); DesktopDescription new_item(name, icon_path, full_path); QList::iterator target_it=qUpperBound(DesktopList.begin(), DesktopList.end(), new_item); int target_ix=target_it-DesktopList.begin(); @@ -89,20 +90,16 @@ void DesktopModel::FinishList() void DesktopSource::run() { QDir AppScreenDir; - DesktopFile CurrentDesktop; AppScreenDir.setFilter(QDir::Files|QDir::NoSymLinks|QDir::NoDotAndDotDot|QDir::Readable|QDir::CaseSensitive); AppScreenDir.setNameFilters(QStringList()<<"*.desktop"); AppScreenDir.setPath("/usr/share/applications/"); - QString icon, name; - foreach (const QFileInfo &file, AppScreenDir.entryInfoList()) { - CurrentDesktop.Open(file.absoluteFilePath()); - if (CurrentDesktop.DesktopKeyValue("NotShowIn", false, name)&&name=="X-MeeGo") continue; - if (!CurrentDesktop.DesktopKeyValue("Name", true, name)) continue; - if (!CurrentDesktop.DesktopKeyValue("Icon", true, icon)) continue; - signalNewEntry(name, DesktopFile::DesktopIconPath(icon), file.absoluteFilePath()); //"QPixmap: It is not safe to use pixmaps outside the GUI thread" - //signalNewEntry(name, icon, path); + MDesktopEntry CurrentDesktop(file.absoluteFilePath()); + if (!CurrentDesktop.isValid()) continue; + if (CurrentDesktop.notShowIn().contains("X-MeeGo")) continue; + signalNewEntry(CurrentDesktop.name(), IconProvider::ConvertPath(CurrentDesktop.icon()), file.absoluteFilePath()); //"QPixmap: It is not safe to use pixmaps outside the GUI thread" + //signalNewEntry(CurrentDesktop.name(), CurrentDesktop.icon(), file.absoluteFilePath()); } signalSourceDepleted(); diff --git a/src/desktoptools.cpp b/src/desktoptools.cpp deleted file mode 100644 index 3c4120a..0000000 --- a/src/desktoptools.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * HMTsu - * Copyright (C) 2013 Lcferrum - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "iconprovider.h" -#include "desktoptools.h" - -DesktopFile::DesktopFile(): - desktop(NULL), lang_full(QLocale::system().name()), lang_short(QLocale::system().language()) -{ -} - -DesktopFile::DesktopFile(const QString &path): - desktop(NULL), lang_full(QLocale::system().name()), lang_short(QLocale::system().language()) -{ - Open(path); -} - -DesktopFile::~DesktopFile() -{ - delete desktop; -} - -void DesktopFile::Open(const QString &path) -{ - delete desktop; - desktop=new QSettings(path, QSettings::IniFormat); - desktop->setIniCodec("UTF-8"); - desktop->beginGroup("Desktop Entry"); -} - -bool DesktopFile::IfOpened() const -{ - return desktop; -} - -QString DesktopFile::Path() const -{ - if (desktop) { - return desktop->fileName(); - } else - return ""; -} - - -bool DesktopFile::DesktopKeyValue(const QString &key, bool locval, QString &value) const -{ - if (!desktop) - return false; - - QVariant val=locval?desktop->value(QString("%1[%2]").arg(key, lang_full)):desktop->value(key); - - if (val.isValid()) { - value=val.toString(); - return true; - } else if (locval&&(val=desktop->value(QString("%1[%2]").arg(key, lang_short))).isValid()) { - value=val.toString(); - return true; - } else if (locval&&(val=desktop->value(key)).isValid()) { - value=val.toString(); - return true; - } else { - return false; - } -} - -QString DesktopFile::DesktopIconPath(const QString &icon_value) -{ - if (icon_value.length()>0) - return (access(icon_value.toLocal8Bit().constData(), R_OK)? - (IconProvider::HasIcon(icon_value)?"image://icon/":"image://theme/"): - "file://") - +icon_value; - else - return ""; -} diff --git a/src/desktoptools.h b/src/desktoptools.h deleted file mode 100644 index 3f7984a..0000000 --- a/src/desktoptools.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * HMTsu - * Copyright (C) 2013 Lcferrum - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef DESKTOPTOOLS_H -#define DESKTOPTOOLS_H - -#include - -class DesktopFile { -private: - QSettings* desktop; - QString lang_full; - QString lang_short; -public: - DesktopFile(); - DesktopFile(const QString &path); - ~DesktopFile(); - void Open(const QString &path); - bool IfOpened() const; - QString Path() const; - bool DesktopKeyValue(const QString &key, bool locval, QString &value) const; - static QString DesktopIconPath(const QString &icon_value); -}; - -#endif // DESKTOPTOOLS_H diff --git a/src/iconprovider.cpp b/src/iconprovider.cpp index c46ac53..1c6568b 100644 --- a/src/iconprovider.cpp +++ b/src/iconprovider.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "iconprovider.h" QPixmap IconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) @@ -31,7 +32,13 @@ void IconProvider::SetToCurrentSystemTheme() QIcon::setThemeName(CurrentTheme.value().toString()); } -bool IconProvider::HasIcon(const QString &name) +QString IconProvider::ConvertPath(const QString &icon_path) { - return QIcon::hasThemeIcon(name); + if (icon_path.length()>0) + return (access(icon_path.toLocal8Bit().constData(), R_OK)? + (QIcon::hasThemeIcon(icon_path)?"image://icon/":"image://theme/"): + "file://") + +icon_path; + else + return ""; } diff --git a/src/iconprovider.h b/src/iconprovider.h index 3dbf0f9..b37da95 100644 --- a/src/iconprovider.h +++ b/src/iconprovider.h @@ -22,7 +22,7 @@ class IconProvider: public QDeclarativeImageProvider { QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) {} virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); static void SetToCurrentSystemTheme(); - static bool HasIcon(const QString &name); + static QString ConvertPath(const QString &icon_path); }; #endif // ICONPROVIDER_H diff --git a/src/main.cpp b/src/main.cpp index 0bd9e31..9800bb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,6 @@ #include "common.h" #include "contranslator.h" #include "iconprovider.h" -#include "desktoptools.h" #include "desktopmodel.h" #include "qmlapplicationviewer.h" @@ -40,9 +39,8 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) QScopedPointer App(createApplication(argc, argv)); QTranslator Translator; - if (!(Translator.load("tr_"+QLocale::system().name(), ":/i18n"))) - if (!(Translator.load("tr_"+QLocale::system().language(), ":/i18n"))) - Translator.load("tr_en", ":/i18n"); + if (!Translator.load("tr_"+QLocale::system().name(), ":/i18n")) + Translator.load("tr_en", ":/i18n"); App->installTranslator(&Translator); ConTranslator ConsoleMsgs; diff --git a/src/qml/DesktopItem.qml b/src/qml/DesktopItem.qml index 01cd9ab..b37869f 100644 --- a/src/qml/DesktopItem.qml +++ b/src/qml/DesktopItem.qml @@ -46,7 +46,7 @@ Item { sourceSize.width: 64 sourceSize.height: 64 anchors.verticalCenter: parent.verticalCenter - source: image + source: image===""?"image://theme/icon-l-default-application":image onStatusChanged: { if (status===Image.Error)