Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- git.orig/src/applicationinfo.cpp
- +++ git/src/applicationinfo.cpp
- @@ -10,7 +10,7 @@
- #include <QStandardPaths>
- #endif
- -#ifdef HAVE_X11
- +#ifdef Q_OS_UNIX
- #include <sys/stat.h> // chmod
- #endif
- @@ -36,6 +36,9 @@
- #include "config.h"
- #endif
- +#define xstr(a) str(a)
- +#define str(a) #a
- +
- // Constants. These should be moved to a more 'dynamically changeable'
- // place (like an external file loaded through the resources system)
- // Should also be overridable through an optional file.
- @@ -58,8 +61,8 @@
- #define PROG_APPCAST_URL ""
- #endif
- -#if defined(HAVE_X11) && !defined(PSI_DATADIR)
- -#define PSI_DATADIR "/usr/local/share/psi"
- +#if defined(Q_OS_UNIX) && !defined(PSI_DATADIR)
- +#define PSI_DATADIR xstr(APP_PREFIX)"/share/"xstr(APP_BIN_NAME)
- #endif
- @@ -141,7 +144,7 @@ QString ApplicationInfo::getCertificateS
- QString ApplicationInfo::resourcesDir()
- {
- -#if defined(HAVE_X11)
- +#if defined(Q_OS_UNIX)
- return PSI_DATADIR;
- #elif defined(Q_OS_WIN)
- return qApp->applicationDirPath();
- @@ -238,10 +241,16 @@ QString ApplicationInfo::homeDir(Applica
- QDir configDir(QDir::homePath() + "/Library/Application Support/" + name());
- QDir cacheDir(QDir::homePath() + "/Library/Caches/" + name());
- QDir dataDir(configDir);
- -#elif defined HAVE_X11
- +#elif defined HAVE_FREEDESKTOP
- +#ifndef HAVE_QT5
- QString XdgConfigHome = QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME"));
- QString XdgDataHome = QString::fromLocal8Bit(getenv("XDG_DATA_HOME"));
- QString XdgCacheHome = QString::fromLocal8Bit(getenv("XDG_CACHE_HOME"));
- +#else
- + QString XdgConfigHome(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
- + QString XdgDataHome(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
- + QString XdgCacheHome(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
- +#endif
- if (XdgConfigHome.isEmpty()) {
- XdgConfigHome = QDir::homePath() + "/.config";
- }
- @@ -383,3 +392,14 @@ QString ApplicationInfo::currentProfileD
- {
- return pathToProfile(activeProfile, type);
- }
- +
- +QString ApplicationInfo::desktopFile()
- +{
- + QString dFile;
- + const QString _desktopFile(xstr(APP_PREFIX) "/share/applications/" xstr(APP_BIN_NAME) ".desktop");
- + QFile f(_desktopFile);
- + if(f.open(QIODevice::ReadOnly)) {
- + dFile = QString::fromUtf8(f.readAll());
- + }
- + return dFile;
- +}
- --- git.orig/src/applicationinfo.h
- +++ git/src/applicationinfo.h
- @@ -44,6 +44,9 @@ public:
- static QString optionsNS();
- static QString storageNS();
- static QString fileCacheNS();
- +
- + // Common
- + static QString desktopFile();
- };
- #endif
- --- git.orig/src/options/opt_application.cpp
- +++ git/src/options/opt_application.cpp
- @@ -3,14 +3,30 @@
- #include "iconwidget.h"
- #include "psioptions.h"
- #include "proxy.h"
- +#include "translationmanager.h"
- +#include "varlist.h"
- +#include "applicationinfo.h"
- #include <QCheckBox>
- #include <QComboBox>
- #include <QLineEdit>
- +#include <QSettings>
- #include <QList>
- +#include <QMessageBox>
- +#include <QDir>
- +#ifdef HAVE_QT5
- +#include <QStandardPaths>
- +#endif
- #include "ui_opt_application.h"
- +#ifdef Q_OS_WIN
- + static const QString regString = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- + static const QString psiAutoStart("/.config/autostart/" APP_BIN_NAME ".desktop");
- +#endif
- +
- class OptApplicationUI : public QWidget, public Ui::OptApplication
- {
- public:
- @@ -53,6 +69,7 @@ QWidget *OptionsTabApplication::widget()
- #ifdef Q_OS_MAC
- d->gb_docklet->hide();
- + d->ck_auto_load->hide();
- #endif
- if (!haveAutoUpdater_) {
- @@ -101,6 +118,51 @@ void OptionsTabApplication::applyOptions
- //Proxy
- ProxyManager::instance()->proxyForObject()->save();
- +
- + // Language
- + QString curLang = TranslationManager::instance()->currentLanguage();
- + QString lang = d->cb_lang->currentText();
- + QString itemData;
- + foreach(VarListItem it, TranslationManager::instance()->availableTranslations() ) {
- + if(it.data() == lang) {
- + itemData = it.key();
- + break;
- + }
- + }
- + if(curLang != itemData && !itemData.isEmpty()) {
- + TranslationManager::instance()->loadTranslation(itemData);
- + QMessageBox::information(0, tr("Information"), tr("Some of the options you changed will only have full effect upon restart."));
- + }
- + QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
- + s.setValue("last_lang", itemData);
- +
- + //Auto-load
- +#ifdef Q_OS_WIN
- + QSettings set(regString, QSettings::NativeFormat);
- + if(d->ck_auto_load->isChecked()) {
- + set.setValue(ApplicationInfo::name(), QDir::toNativeSeparators(qApp->applicationFilePath()));
- + }
- + else {
- + set.remove(ApplicationInfo::name());
- + }
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- +#ifndef HAVE_QT5
- + QDir home(QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME")));
- +#else
- + QDir home(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
- +#endif
- +
- + if (!home.exists("autostart")) {
- + home.mkpath("autostart");
- + }
- + QFile f(home.absolutePath() + psiAutoStart);
- + if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
- + const QString contents = ApplicationInfo::desktopFile().trimmed();
- + f.write(contents.toUtf8());
- + f.write(QString("\nHidden=%1").arg(d->ck_auto_load->isChecked() ? "false\n" : "true\n").toUtf8());
- + }
- +#endif
- }
- void OptionsTabApplication::restoreOptions()
- @@ -123,6 +185,36 @@ void OptionsTabApplication::restoreOptio
- // data transfer
- d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
- d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );
- +
- + // Language
- + VarList vList = TranslationManager::instance()->availableTranslations();
- + QStringList lang = vList.varsToStringList();
- + d->cb_lang->addItem(tr("Default"));
- + foreach(QString item, lang) {
- + d->cb_lang->addItem(vList.get(item));
- + }
- + QString curLang = TranslationManager::instance()->currentLanguage();
- + QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
- + QString curL = s.value("last_lang", "").toString();
- + if (curL.isEmpty())
- + d->cb_lang->setCurrentIndex( 0 );
- + else if(!curLang.isEmpty() && lang.contains(curLang) )
- + d->cb_lang->setCurrentIndex( d->cb_lang->findText(vList.get(curLang)) );
- +
- + //Auto-load
- +#ifdef Q_OS_WIN
- + QSettings set(regString, QSettings::NativeFormat);
- + const QString path = set.value(ApplicationInfo::name()).toString();
- + d->ck_auto_load->setChecked( (path == QDir::toNativeSeparators(qApp->applicationFilePath())) );
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- + QFile desktop(QDir::homePath() + psiAutoStart);
- + if (desktop.open(QIODevice::ReadOnly)
- + && QString(desktop.readAll()).contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive)))
- + {
- + d->ck_auto_load->setChecked(true);
- + }
- +#endif
- }
- void OptionsTabApplication::doEnableQuitOnClose(int state)
- --- git.orig/src/options/opt_application.ui
- +++ git/src/options/opt_application.ui
- @@ -13,6 +13,13 @@
- <string>OptApplicationUI</string>
- </property>
- <layout class="QVBoxLayout" >
- + <item>
- + <widget class="QCheckBox" name="ck_auto_load">
- + <property name="text">
- + <string>Automatically launch application when OS starts</string>
- + </property>
- + </widget>
- + </item>
- <item>
- <widget class="QCheckBox" name="ck_docklet" >
- <property name="text" >
- @@ -179,6 +186,33 @@
- </widget>
- </item>
- <item>
- + <layout class="QHBoxLayout" name="horizontalLayout">
- + <item>
- + <widget class="QLabel" name="label_2">
- + <property name="text">
- + <string>Language</string>
- + </property>
- + </widget>
- + </item>
- + <item>
- + <widget class="QComboBox" name="cb_lang"/>
- + </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>
- + <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- --- git.orig/src/src.pri
- +++ git/src/src.pri
- @@ -9,7 +9,10 @@ greaterThan(QT_MAJOR_VERSION, 4) {
- QT += x11extras
- }
- }
- -unix:!mac:DEFINES += HAVE_X11
- +unix:!mac {
- + DEFINES += HAVE_X11
- + DEFINES += HAVE_FREEDESKTOP
- +}
- CONFIG(debug, debug|release) {
- mac: DEFINES += DEBUG_POSTFIX=\\\"_debug\\\"
- --- git.orig/src/src.pro
- +++ git/src/src.pro
- @@ -32,6 +32,8 @@ include(../qa/oldtest/unittest.pri)
- include($$top_builddir/conf.pri)
- unix {
- + DEFINES += APP_PREFIX=$$PREFIX
- + DEFINES += APP_BIN_NAME=$$target
- # Target
- target.path = $$BINDIR
- INSTALLS += target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement