commit 1a4249ab2e678349c508dc1d6bdbf85a638d311b Author: Tomás Touceda chiiph@torproject.org Date: Thu Sep 1 15:56:39 2011 -0300
Improve Jason's patch with Matt's suggestions --- pkg/osx/MacOSXBundleInfo.plist.in | 38 -------------------------------- src/vidalia/CMakeLists.txt | 7 ++++- src/vidalia/HelperProcess.cpp | 17 ++++++++++++++ src/vidalia/HelperProcess.h | 2 + src/vidalia/MainWindow.cpp | 6 +++- src/vidalia/config/AppearancePage.cpp | 24 ++++++++++---------- src/vidalia/config/VidaliaSettings.cpp | 33 +++++++++++++++++++++------ src/vidalia/config/VidaliaSettings.h | 12 ++++++++- 8 files changed, 76 insertions(+), 63 deletions(-)
diff --git a/pkg/osx/MacOSXBundleInfo.plist.in b/pkg/osx/MacOSXBundleInfo.plist.in deleted file mode 100644 index 3b5bfe0..0000000 --- a/pkg/osx/MacOSXBundleInfo.plist.in +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDevelopmentRegion</key> - <string>English</string> - <key>CFBundleExecutable</key> - <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> - <key>CFBundleGetInfoString</key> - <string>${MACOSX_BUNDLE_INFO_STRING}</string> - <key>CFBundleIconFile</key> - <string>${MACOSX_BUNDLE_ICON_FILE}</string> - <key>CFBundleIdentifier</key> - <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleLongVersionString</key> - <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string> - <key>CFBundleName</key> - <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleShortVersionString</key> - <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> - <key>CSResourcesFileMapped</key> - <true/> - <key>LSRequiresCarbon</key> - <true/> - <key>NSHumanReadableCopyright</key> - <string>${MACOSX_BUNDLE_COPYRIGHT}</string> - <key>LSUIElement</key> - <string>1</string> -</dict> -</plist> diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt index be3e012..52ba510 100644 --- a/src/vidalia/CMakeLists.txt +++ b/src/vidalia/CMakeLists.txt @@ -361,8 +361,11 @@ if (APPLE) set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/) add_executable(${vidalia_BIN} MACOSX_BUNDLE ${vidalia_SRCS})
- ## Specify location of custom Info.plist file - set_target_properties(${vidalia_BIN} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ../pkg/osx/MacOSXBundleInfo.plist.in) + ## Specify location of custom Info.plist file + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/MacOSXBundleInfo.plist.in + ${CMAKE_CURRENT_BINARY_DIR}/MacOSXBundleInfo.plist) + set_target_properties(${vidalia_BIN} PROPERTIES MACOSX_BUNDLE_INFO_PLIST + ${CMAKE_CURRENT_BINARY_DIR}/MacOSXBundleInfo.plist)
## Get the location of the app bundle for the current configuration get_target_property(VIDALIA_EXECUTABLE ${vidalia_BIN} LOCATION) diff --git a/src/vidalia/HelperProcess.cpp b/src/vidalia/HelperProcess.cpp index 0abc848..b80f151 100644 --- a/src/vidalia/HelperProcess.cpp +++ b/src/vidalia/HelperProcess.cpp @@ -45,6 +45,9 @@ #include <QString> #include <QFileInfo>
+#ifdef Q_WS_MAC +#include <Carbon/Carbon.h> +#endif
/** Default constructor */ HelperProcess::HelperProcess(QObject *parent) @@ -131,3 +134,17 @@ HelperProcess::isDone() const return state() == NotRunning; }
+void +HelperProcess::toForeground() +{ +#if defined(Q_WS_MAC) + ProcessSerialNumber psn; + OSStatus st; + + do { + st = GetProcessForPID(pid(), &psn); + } while(st == -600); + + SetFrontProcess(&psn); +#endif +} diff --git a/src/vidalia/HelperProcess.h b/src/vidalia/HelperProcess.h index cf2b234..62aef98 100644 --- a/src/vidalia/HelperProcess.h +++ b/src/vidalia/HelperProcess.h @@ -58,6 +58,8 @@ public: void start(const QString &app, const QStringList &args); /** Returns true iff process is not running. */ bool isDone() const; + /** Bring process to foreground */ + void toForeground();
signals: /** Invoked when start() fails. */ diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp index 967e2df..d646ebe 100644 --- a/src/vidalia/MainWindow.cpp +++ b/src/vidalia/MainWindow.cpp @@ -222,7 +222,7 @@ MainWindow::MainWindow()
#if defined(Q_WS_MAC) /* Display OSX dock icon if icon preference is not set to "Tray Only" */ - if (settings.getIconPref() != "Tray") { + if (settings.getIconPref() != VidaliaSettings::Tray) { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); } @@ -589,7 +589,7 @@ MainWindow::setTrayIcon(const QString &iconFile) VidaliaSettings settings; QApplication::setWindowIcon(QPixmap(iconFile)); /* only display tray icon if icon preference is not set to "Dock Only" */ - if (settings.getIconPref() != "Dock") + if (settings.getIconPref() != VidaliaSettings::Dock) _trayIcon.setIcon(QIcon(iconFile)); #else /* always display tray icon for other platforms */ @@ -648,6 +648,7 @@ MainWindow::launchBrowserFromDirectory()
/* Launch the browser */ _browserProcess->start(browserExecutable, commandLine); + _browserProcess->toForeground(); }
/** Starts the web browser and IM client, if appropriately configured */ @@ -665,6 +666,7 @@ MainWindow::startSubprocesses() /* BrowserDirectory is not set, but BrowserExecutable is; use this */ _browserProcess->setEnvironment(updateBrowserEnv()); _browserProcess->start(subprocess, QStringList()); + _browserProcess->toForeground(); }
/* Launch the IM client */ diff --git a/src/vidalia/config/AppearancePage.cpp b/src/vidalia/config/AppearancePage.cpp index 647b67a..95998e9 100644 --- a/src/vidalia/config/AppearancePage.cpp +++ b/src/vidalia/config/AppearancePage.cpp @@ -76,14 +76,14 @@ AppearancePage::save(QString &errmsg) #if defined(Q_WS_MAC) /* Save new icon preference */ if(ui.rdoIconPrefDock->isChecked()) { - _settings->setIconPref("Dock"); + _settings->setIconPref(VidaliaSettings::Dock); } else if(ui.rdoIconPrefTray->isChecked()) { - _settings->setIconPref("Tray"); + _settings->setIconPref(VidaliaSettings::Tray); } else { /* default setting */ - _settings->setIconPref("Both"); + _settings->setIconPref(VidaliaSettings::Both); } #endif
@@ -101,16 +101,16 @@ AppearancePage::load() ui.cmboStyle->setCurrentIndex(index);
#if defined(Q_WS_MAC) - /* set current icon preference */ - ui.rdoIconPrefBoth->setChecked(_settings->getIconPref() == "Both"); - ui.rdoIconPrefTray->setChecked(_settings->getIconPref() == "Tray"); - ui.rdoIconPrefDock->setChecked(_settings->getIconPref() == "Dock"); + /* set current icon preference */ + ui.rdoIconPrefBoth->setChecked(_settings->getIconPref() == VidaliaSettings::Both); + ui.rdoIconPrefTray->setChecked(_settings->getIconPref() == VidaliaSettings::Tray); + ui.rdoIconPrefDock->setChecked(_settings->getIconPref() == VidaliaSettings::Dock); #else - /* hide preference on non-OSX platforms */ - ui.grpIconPref->setVisible(false); - ui.rdoIconPrefBoth->setVisible(false); - ui.rdoIconPrefTray->setVisible(false); - ui.rdoIconPrefDock->setVisible(false); + /* hide preference on non-OSX platforms */ + ui.grpIconPref->setVisible(false); + ui.rdoIconPrefBoth->setVisible(false); + ui.rdoIconPrefTray->setVisible(false); + ui.rdoIconPrefDock->setVisible(false); #endif }
diff --git a/src/vidalia/config/VidaliaSettings.cpp b/src/vidalia/config/VidaliaSettings.cpp index 858ca8e..85b70e9 100644 --- a/src/vidalia/config/VidaliaSettings.cpp +++ b/src/vidalia/config/VidaliaSettings.cpp @@ -46,7 +46,7 @@ #endif
#if defined(Q_WS_MAC) -#define SETTING_ICON_PREF "IconPref" +#define SETTING_ICON_PREF "IconDisplayPreference" #endif
/** Default Constructor */ @@ -85,7 +85,7 @@ VidaliaSettings::VidaliaSettings() setDefault(SETTING_LAST_UPDATE_CHECK, QDateTime()); setDefault(SETTING_USE_LOCAL_GEOIP_DATABASE, false); setDefault(SETTING_LOCAL_GEOIP_DATABASE, ""); - setDefault(SETTING_ICON_PREF, "Both"); + setDefault(SETTING_ICON_PREF, Both); }
/** Gets the currently preferred language code for Vidalia. */ @@ -326,15 +326,34 @@ VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile) }
/** Get the icon preference */ -QString -VidaliaSettings::getIconPref() const +VidaliaSettings::IconPosition +VidaliaSettings::getIconPref() { - return value(SETTING_ICON_PREF).toString(); + return fromString(value(SETTING_ICON_PREF).toString()); }
/** Set the icon preference */ void -VidaliaSettings::setIconPref(const QString &iconPref) +VidaliaSettings::setIconPref(const IconPosition iconPref) +{ + setValue(SETTING_ICON_PREF, toString(iconPref)); +} + +QString +VidaliaSettings::toString(const IconPosition iconPref) { - setValue(SETTING_ICON_PREF, iconPref); + switch(iconPref) { + case Dock: return "Dock"; + case Tray: return "Tray"; + default: return "Both"; + } +} + +VidaliaSettings::IconPosition +VidaliaSettings::fromString(QString iconPref) +{ + if(iconPref == "Dock") return Dock; + if(iconPref == "Tray") return Tray; + + return Both; } diff --git a/src/vidalia/config/VidaliaSettings.h b/src/vidalia/config/VidaliaSettings.h index 2efec12..6cbdefb 100644 --- a/src/vidalia/config/VidaliaSettings.h +++ b/src/vidalia/config/VidaliaSettings.h @@ -33,6 +33,12 @@ class VidaliaSettings : public VSettings Q_OBJECT
public: + enum IconPosition { + Tray, + Dock, + Both, + }; + /** Default constructor. */ VidaliaSettings();
@@ -127,10 +133,12 @@ public: void setLocalGeoIpDatabase(const QString &databaseFile);
/** Get the icon preference */ - QString getIconPref() const; + IconPosition getIconPref();
/** Set the icon preference */ - void setIconPref(const QString &iconPref); + void setIconPref(const IconPosition iconPref); + QString toString(const IconPosition iconPref); + IconPosition fromString(QString iconPref); };
#endif
tor-commits@lists.torproject.org