OSX builds should also use QtSingleApplication?

This commit is contained in:
craig.p.drummond
2014-04-18 22:42:49 +00:00
committed by craig.p.drummond
parent d5be27ec33
commit 4f0de55117
4 changed files with 16 additions and 69 deletions

View File

@@ -631,10 +631,10 @@ else (ENABLE_KDE)
endif (WIN32)
set(XDG_APPS_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
if (WIN32)
if (WIN32 OR APPLE)
add_subdirectory(3rdparty/qtsingleapplication)
target_link_libraries(cantata qtsingleapplication)
endif (WIN32)
endif (WIN32 OR APPLE)
if (WIN32 OR (NOT APPLE AND NOT ENABLE_QT5))
target_link_libraries(cantata qxt)
endif (WIN32 OR (NOT APPLE AND NOT ENABLE_QT5))

View File

@@ -137,16 +137,22 @@ void Application::mwDestroyed(QObject *obj)
}
}
#elif defined Q_OS_WIN
#elif defined Q_OS_WIN || Q_OS_MAC
Application::Application(int &argc, char **argv)
: QtSingleApplication(argc, argv)
{
connect(this, SIGNAL(messageReceived(const QString &)), SLOT(message(const QString &)));
#if defined Q_OS_WIN2
connect(this, SIGNAL(reconnect()), MPDConnection::self(), SLOT(reconnect()));
#endif
}
static void setupIconTheme()
{
#ifdef Q_OS_MAC
//QIcon::setThemeSearchPaths(QStringList(QCoreApplication::applicationDirPath() + "/../Resources/icons"));
QIcon::setThemeName(QLatin1String("oxygen"));
#else
QString cfgTheme=Settings::self()->iconTheme();
if (!cfgTheme.isEmpty()) {
QIcon::setThemeName(cfgTheme);
@@ -163,8 +169,10 @@ static void setupIconTheme()
}
}
}
#endif
}
#if defined Q_OS_WIN2
bool Application::winEventFilter(MSG *msg, long *result)
{
if (msg && WM_POWERBROADCAST==msg->message && PBT_APMRESUMEAUTOMATIC==msg->wParam) {
@@ -172,6 +180,7 @@ bool Application::winEventFilter(MSG *msg, long *result)
}
return QCoreApplication::winEventFilter(msg, result);
}
#endif
bool Application::start()
{
@@ -228,53 +237,6 @@ void Application::load(const QStringList &files)
}
}
#elif defined Q_OS_MAC
Application::Application(int &argc, char **argv)
: QApplication(argc, argv)
{
connect(this, SIGNAL(messageReceived(const QString &)), SLOT(message(const QString &)));
connect(this, SIGNAL(reconnect()), MPDConnection::self(), SLOT(reconnect()));
}
void Application::setupIconTheme()
{
//QIcon::setThemeSearchPaths(QStringList(QCoreApplication::applicationDirPath() + "/../Resources/icons"));
QIcon::setThemeName(QLatin1String("oxygen"));
}
bool Application::start()
{
setupIconTheme();
return true;
}
void Application::loadFiles()
{
QStringList args(arguments());
if (args.count()>1) {
args.takeAt(0);
load(args);
}
}
void Application::load(const QStringList &files)
{
if (files.isEmpty()) {
return;
}
QStringList urls;
foreach (const QString &f, files) {
urls.append(f);
}
if (!urls.isEmpty()) {
MainWindow *mw=qobject_cast<MainWindow *>(activationWindow());
if (mw) {
mw->load(urls);
}
}
}
#else // Q_OS_WIN || Q_OS_MAC
#include <QDBusConnection>
#include <QDBusMessage>

View File

@@ -49,7 +49,7 @@ private Q_SLOTS:
private:
MainWindow *w;
};
#elif defined Q_OS_WIN || defined WIN32 // moc does not seem to see Q_OS_WIN, but will see WIN32 :-(
#elif defined Q_OS_WIN || defined WIN32 || Q_OS_MAC || defined __APPLE__ // moc does not seem to see Q_OS_WIN/Q_OS_MAC,, but will see WIN32/__APPLE__ :-(
#include "qtsingleapplication/qtsingleapplication.h"
class Application : public QtSingleApplication
{
@@ -60,7 +60,9 @@ public:
Application(int &argc, char **argv);
virtual ~Application() { }
#if defined Q_OS_WIN || defined WIN32
bool winEventFilter(MSG *msg, long *result);
#endif
bool start();
void loadFiles();
@@ -73,22 +75,6 @@ private Q_SLOTS:
Q_SIGNALS:
void reconnect();
};
#elif defined Q_OS_MAC || defined __APPLE__ // moc does not seem to see Q_OS_MAC, but will see __APPLE__ :-(
#include <QApplication>
class Application : public QApplication
{
public:
static void initObjects();
Application(int &argc, char **argv);
virtual ~Application() { }
bool start();
void loadFiles();
void setupIconTheme();
private:
void load(const QStringList &files);
};
#else
#include <QApplication>
class Application : public QApplication
@@ -100,7 +86,6 @@ public:
bool start();
void loadFiles();
void setActivationWindow(QWidget *) { }
void setupIconTheme();
};
#endif

View File

@@ -316,7 +316,7 @@ int main(int argc, char *argv[])
}
}
MainWindow mw;
#if !defined Q_OS_MAC
#if defined Q_OS_WIN || defined Q_OS_MAC
app.setActivationWindow(&mw);
#endif // !defined Q_OS_MAC
app.loadFiles();