Skip to content

Commit

Permalink
MDesktopEntry, better locale handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lcferrum committed Dec 15, 2013
1 parent 4024dbf commit 53c683e
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 179 deletions.
25 changes: 14 additions & 11 deletions data/i18n/conmsgs.ts
Expand Up @@ -4,32 +4,35 @@
<context>
<name>Messages</name>
<message>
<location filename="../../src/context.cpp" line="136"/>
<location filename="../../src/context.cpp" line="138"/>
<source>__context_verbosity_err__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/context.cpp" line="161"/>
<location filename="../../src/context.cpp" line="163"/>
<source>__context_printpass_err__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/context.cpp" line="306"/>
<location filename="../../src/context.cpp" line="332"/>
<source>__context_badinvoke_wrn__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/context.cpp" line="262"/>
<location filename="../../src/context.cpp" line="265"/>
<location filename="../../src/context.cpp" line="276"/>
<location filename="../../src/context.cpp" line="287"/>
<location filename="../../src/context.cpp" line="343"/>
<source>__context_descfile_wrn%1%2__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/context.cpp" line="151"/>
<location filename="../../src/context.cpp" line="153"/>
<source>__context_nodesktop_err__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/context.cpp" line="240"/>
<location filename="../../src/context.cpp" line="242"/>
<source>__context_wordexp_wrn__</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -132,13 +135,13 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/qml/PassPage.qml" line="104"/>
<location filename="../../src/qml/PassPage.qml" line="115"/>
<source>__enter_pass__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/qml/PassPage.qml" line="161"/>
<location filename="../../src/qml/PassPage.qml" line="173"/>
<location filename="../../src/qml/PassPage.qml" line="172"/>
<location filename="../../src/qml/PassPage.qml" line="184"/>
<source>__launch__</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -216,12 +219,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/qml/StartPage.qml" line="202"/>
<location filename="../../src/qml/StartPage.qml" line="194"/>
<source>__select_app__</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/qml/StartPage.qml" line="242"/>
<location filename="../../src/qml/StartPage.qml" line="195"/>
<source>__app_selected__</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 1 addition & 3 deletions hmtsu.pro
Expand Up @@ -10,7 +10,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# 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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Expand Up @@ -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
Expand Down
70 changes: 49 additions & 21 deletions src/context.cpp
Expand Up @@ -19,10 +19,12 @@
#include <pwd.h>
#include <iostream>
#include <QCoreApplication>
#include <QScopedPointer>
#include <QRegExp>
#include <QStringList>
#include <QProcess>
#include <QFileInfo>
#include "iconprovider.h"
#include "context.h"
#include "common.h"
#include "pswtools.h"
Expand Down Expand Up @@ -62,7 +64,7 @@ Context::Context(int argc, char **argv):

int opt=0;
bool use_desktop_file=false;
DesktopFile CurDesktopFile;
QScopedPointer<MDesktopEntry> CurDesktopFile(NULL);

winsize argp;
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &argp)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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__"));
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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="";
}
Expand All @@ -339,7 +367,7 @@ int Context::GetVerboseLevel()

QString Context::GetIcon()
{
return DesktopFile::DesktopIconPath(icon);
return IconProvider::ConvertPath(icon);
}

QString Context::GetRootName()
Expand Down
8 changes: 5 additions & 3 deletions src/context.h
Expand Up @@ -17,9 +17,9 @@
#include <QString>
#include <QDeclarativeContext>
#include <QStringList>
#include <MDesktopEntry>
#include "runtools.h"
#include "runmodes.h"
#include "desktoptools.h"
#include "commhandler.h"

class Context: public QObject, protected IntercomHandler {
Expand All @@ -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();
Expand Down
19 changes: 8 additions & 11 deletions src/desktopmodel.cpp
Expand Up @@ -14,7 +14,8 @@
#include <QStringList>
#include <QDir>
#include <QtAlgorithms>
#include "desktoptools.h"
#include <MDesktopEntry>
#include "iconprovider.h"
#include "desktopmodel.h"

#define THREAD_TIMEOUT 10000 //10 seconds
Expand Down Expand Up @@ -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<DesktopDescription>::iterator target_it=qUpperBound(DesktopList.begin(), DesktopList.end(), new_item);
int target_ix=target_it-DesktopList.begin();
Expand All @@ -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();
Expand Down

0 comments on commit 53c683e

Please sign in to comment.