Clementine-audio-player-Mac.../src/main.cpp

148 lines
4.4 KiB
C++
Raw Normal View History

/* This file is part of Clementine.
Clementine 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.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef Q_OS_WIN32
# define _WIN32_WINNT 0x0500
# include <windows.h>
# include <iostream>
#endif // Q_OS_WIN32
2009-12-24 20:16:07 +01:00
#include "directory.h"
#include "lastfmservice.h"
#include "mainwindow.h"
#include "player.h"
2009-12-24 20:16:07 +01:00
#include "song.h"
2010-04-07 19:39:07 +02:00
#include "equalizer.h"
#include "potranslator.h"
#include "commandlineoptions.h"
2009-12-24 20:16:07 +01:00
2010-01-17 17:10:26 +01:00
#include <QtSingleApplication>
#include <QtDebug>
2010-02-23 19:33:09 +01:00
#include <QLibraryInfo>
#include <QTranslator>
#include <QDir>
2010-03-03 21:35:19 +01:00
#include <QNetworkAccessManager>
2010-03-24 22:34:32 +01:00
#ifdef Q_WS_X11
# include <QDBusConnection>
# include <QDBusMetaType>
# include "mpris.h"
# include "osd.h"
2010-03-24 22:34:32 +01:00
#endif
2009-12-24 20:16:07 +01:00
#include "mac_startup.h"
// Load sqlite plugin on windows
#ifdef WIN32
# include <QtPlugin>
Q_IMPORT_PLUGIN(qsqlite)
#endif
void LoadTranslation(const QString& prefix, const QString& path) {
2010-03-25 13:57:11 +01:00
#if QT_VERSION < 0x040700
// QTranslator::load will try to open and read "clementine" if it exists,
// without checking if it's a file first.
2010-03-25 13:57:11 +01:00
// This was fixed in Qt 4.7
QFileInfo maybe_clementine_directory(path + "/clementine");
if (maybe_clementine_directory.exists() && !maybe_clementine_directory.isFile())
return;
2010-03-25 13:57:11 +01:00
#endif
QTranslator* t = new PoTranslator;
if (t->load(prefix + "_" + QLocale::system().name(), path))
QCoreApplication::installTranslator(t);
else
delete t;
}
2009-12-24 20:16:07 +01:00
int main(int argc, char *argv[]) {
#ifdef Q_OS_DARWIN
// Do Mac specific startup to get media keys working.
// This must go before QApplication initialisation.
mac::MacMain();
#endif
2010-01-08 17:21:22 +01:00
QCoreApplication::setApplicationName("Clementine");
2010-03-22 14:20:30 +01:00
QCoreApplication::setApplicationVersion("0.2");
2010-01-08 17:21:22 +01:00
QCoreApplication::setOrganizationName("Clementine");
2009-12-24 20:16:07 +01:00
QCoreApplication::setOrganizationDomain("davidsansome.com");
qRegisterMetaType<Directory>("Directory");
2009-12-24 20:16:07 +01:00
qRegisterMetaType<DirectoryList>("DirectoryList");
qRegisterMetaType<Subdirectory>("Subdirectory");
qRegisterMetaType<SubdirectoryList>("SubdirectoryList");
2009-12-24 20:16:07 +01:00
qRegisterMetaType<SongList>("SongList");
2010-04-04 22:45:03 +02:00
qRegisterMetaType<Engine::State>("Engine::State");
2010-04-07 19:39:07 +02:00
qRegisterMetaType<Equalizer::Params>("Equalizer::Params");
qRegisterMetaTypeStreamOperators<Equalizer::Params>("Equalizer::Params");
2009-12-24 20:16:07 +01:00
lastfm::ws::ApiKey = LastFMService::kApiKey;
lastfm::ws::SharedSecret = LastFMService::kSecret;
2010-01-17 17:10:26 +01:00
QtSingleApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
2010-01-17 17:10:26 +01:00
// Resources
Q_INIT_RESOURCE(data);
Q_INIT_RESOURCE(translations);
2010-02-23 19:33:09 +01:00
// Translations
LoadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
LoadTranslation("clementine", ":/translations");
LoadTranslation("clementine", a.applicationDirPath());
LoadTranslation("clementine", QDir::currentPath());
CommandlineOptions options(argc, argv);
if (!options.Parse())
return 1;
if (a.isRunning()) {
if (options.is_empty())
qDebug() << "Clementine is already running - activating existing window";
if (a.sendMessage(options.Serialize()))
return 0;
// Couldn't send the message so start anyway
}
2010-03-03 21:35:19 +01:00
QNetworkAccessManager network;
2010-03-24 22:07:16 +01:00
// MPRIS DBus interface.
#ifdef Q_WS_X11
qDBusRegisterMetaType<DBusStatus>();
qDBusRegisterMetaType<Version>();
qDBusRegisterMetaType<QImage>();
QDBusConnection::sessionBus().registerService("org.mpris.clementine");
MPRIS mpris;
2010-03-24 22:07:16 +01:00
#endif
2010-04-12 14:36:30 +02:00
#ifdef Q_OS_DARWIN
QString scanner_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gst-plugin-scanner";
QString plugin_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gstreamer";
setenv("GST_PLUGIN_SCANNER", scanner_path.toAscii().constData(), 1);
setenv("GST_PLUGIN_PATH", plugin_path.toAscii().constData(), 1);
#endif
2010-02-23 19:33:09 +01:00
// Window
MainWindow w(&network);
2010-01-17 17:10:26 +01:00
QObject::connect(&a, SIGNAL(messageReceived(QByteArray)), &w, SLOT(CommandlineOptionsReceived(QByteArray)));
w.CommandlineOptionsReceived(options);
2009-12-24 20:16:07 +01:00
return a.exec();
}