2010-03-24 00:11:46 +01:00
|
|
|
/* 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/>.
|
|
|
|
*/
|
|
|
|
|
2010-02-14 21:08:24 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
# define _WIN32_WINNT 0x0500
|
|
|
|
# include <windows.h>
|
|
|
|
# include <iostream>
|
|
|
|
#endif // Q_OS_WIN32
|
|
|
|
|
2010-05-03 15:58:41 +02:00
|
|
|
#include "config.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/commandlineoptions.h"
|
|
|
|
#include "core/mac_startup.h"
|
|
|
|
#include "core/networkaccessmanager.h"
|
|
|
|
#include "core/player.h"
|
|
|
|
#include "core/potranslator.h"
|
|
|
|
#include "core/song.h"
|
|
|
|
#include "engines/enginebase.h"
|
|
|
|
#include "library/directory.h"
|
|
|
|
#include "radio/lastfmservice.h"
|
|
|
|
#include "ui/equalizer.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui/mainwindow.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>
|
2010-03-02 18:29:43 +01:00
|
|
|
#include <QDir>
|
2010-03-24 22:34:32 +01:00
|
|
|
|
2010-04-30 21:45:43 +02:00
|
|
|
#include <glib/gutils.h>
|
|
|
|
|
2010-03-24 22:34:32 +01:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
# include <QDBusConnection>
|
|
|
|
# include <QDBusMetaType>
|
2010-05-10 23:50:31 +02:00
|
|
|
# include "core/mpris.h"
|
|
|
|
# include "widgets/osd.h"
|
2010-03-24 22:34:32 +01:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-13 21:43:08 +02:00
|
|
|
// Load sqlite plugin on windows and mac.
|
|
|
|
#ifndef Q_WS_X11
|
2010-03-22 19:35:31 +01:00
|
|
|
# include <QtPlugin>
|
|
|
|
Q_IMPORT_PLUGIN(qsqlite)
|
|
|
|
#endif
|
|
|
|
|
2010-03-02 18:48:56 +01:00
|
|
|
void LoadTranslation(const QString& prefix, const QString& path) {
|
2010-03-25 13:57:11 +01:00
|
|
|
#if QT_VERSION < 0x040700
|
2010-03-23 19:00:55 +01:00
|
|
|
// 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
|
2010-03-23 19:00:55 +01:00
|
|
|
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
|
2010-03-23 19:00:55 +01:00
|
|
|
|
2010-04-08 16:29:08 +02:00
|
|
|
QTranslator* t = new PoTranslator;
|
2010-03-23 19:00:55 +01:00
|
|
|
if (t->load(prefix + "_" + QLocale::system().name(), path))
|
|
|
|
QCoreApplication::installTranslator(t);
|
|
|
|
else
|
|
|
|
delete t;
|
2010-03-02 18:48:56 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2010-04-13 15:55:54 +02:00
|
|
|
#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-05-03 15:58:41 +02:00
|
|
|
QCoreApplication::setApplicationVersion(CLEMENTINE_VERSION_STRING);
|
2010-01-08 17:21:22 +01:00
|
|
|
QCoreApplication::setOrganizationName("Clementine");
|
2009-12-24 20:16:07 +01:00
|
|
|
QCoreApplication::setOrganizationDomain("davidsansome.com");
|
|
|
|
|
2010-04-30 21:45:43 +02:00
|
|
|
// This makes us show up nicely in gnome-volume-control
|
|
|
|
g_set_application_name(QCoreApplication::applicationName().toLocal8Bit());
|
|
|
|
|
2010-04-01 18:59:32 +02:00
|
|
|
qRegisterMetaType<Directory>("Directory");
|
2009-12-24 20:16:07 +01:00
|
|
|
qRegisterMetaType<DirectoryList>("DirectoryList");
|
2010-04-01 18:59:32 +02:00
|
|
|
qRegisterMetaType<Subdirectory>("Subdirectory");
|
|
|
|
qRegisterMetaType<SubdirectoryList>("SubdirectoryList");
|
2009-12-24 20:16:07 +01:00
|
|
|
qRegisterMetaType<SongList>("SongList");
|
2010-04-15 00:05:41 +02:00
|
|
|
qRegisterMetaType<PlaylistItemList>("PlaylistItemList");
|
2010-04-04 22:45:03 +02:00
|
|
|
qRegisterMetaType<Engine::State>("Engine::State");
|
2010-04-15 01:59:11 +02:00
|
|
|
qRegisterMetaType<Engine::SimpleMetaBundle>("Engine::SimpleMetaBundle");
|
2010-04-07 19:39:07 +02:00
|
|
|
qRegisterMetaType<Equalizer::Params>("Equalizer::Params");
|
|
|
|
qRegisterMetaTypeStreamOperators<Equalizer::Params>("Equalizer::Params");
|
2010-05-10 15:15:52 +02:00
|
|
|
qRegisterMetaType<const char*>("const char*");
|
|
|
|
qRegisterMetaType<QNetworkReply*>("QNetworkReply*");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-02-23 20:26:21 +01:00
|
|
|
lastfm::ws::ApiKey = LastFMService::kApiKey;
|
|
|
|
lastfm::ws::SharedSecret = LastFMService::kSecret;
|
|
|
|
|
2010-05-11 14:03:55 +02:00
|
|
|
// Detect technically invalid usage of non-ASCII in ID3v1 tags.
|
|
|
|
UniversalEncodingHandler handler;
|
|
|
|
TagLib::ID3v1::Tag::setStringHandler(&handler);
|
|
|
|
|
2010-01-17 17:10:26 +01:00
|
|
|
QtSingleApplication a(argc, argv);
|
2010-04-07 18:26:04 +02:00
|
|
|
a.setQuitOnLastWindowClosed(false);
|
2010-01-17 17:10:26 +01:00
|
|
|
|
2010-05-01 15:40:21 +02:00
|
|
|
// Gnome on Ubuntu has menu icons disabled by default. I think that's a bad
|
|
|
|
// idea, and makes some menus in Clementine look confusing.
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, false);
|
|
|
|
|
2010-03-01 13:15:15 +01:00
|
|
|
// Resources
|
|
|
|
Q_INIT_RESOURCE(data);
|
2010-03-01 18:36:50 +01:00
|
|
|
Q_INIT_RESOURCE(translations);
|
2010-03-01 13:15:15 +01:00
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Translations
|
2010-03-02 18:48:56 +01:00
|
|
|
LoadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
LoadTranslation("clementine", ":/translations");
|
|
|
|
LoadTranslation("clementine", a.applicationDirPath());
|
|
|
|
LoadTranslation("clementine", QDir::currentPath());
|
2010-03-02 18:29:43 +01:00
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
|
|
|
IconLoader::Init();
|
|
|
|
|
2010-04-13 00:44:29 +02:00
|
|
|
|
|
|
|
CommandlineOptions options(argc, argv);
|
|
|
|
if (!options.Parse())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (a.isRunning()) {
|
2010-04-21 22:57:54 +02:00
|
|
|
if (options.is_empty()) {
|
2010-04-13 01:35:47 +02:00
|
|
|
qDebug() << "Clementine is already running - activating existing window";
|
2010-04-21 22:57:54 +02:00
|
|
|
}
|
|
|
|
if (a.sendMessage(options.Serialize())) {
|
2010-04-13 00:44:29 +02:00
|
|
|
return 0;
|
2010-04-21 22:57:54 +02:00
|
|
|
}
|
2010-04-13 00:44:29 +02:00
|
|
|
// Couldn't send the message so start anyway
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:15:52 +02:00
|
|
|
NetworkAccessManager network;
|
2010-03-03 21:35:19 +01:00
|
|
|
|
2010-03-24 22:07:16 +01:00
|
|
|
// MPRIS DBus interface.
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
qDBusRegisterMetaType<DBusStatus>();
|
|
|
|
qDBusRegisterMetaType<Version>();
|
2010-03-25 18:52:28 +01:00
|
|
|
qDBusRegisterMetaType<QImage>();
|
2010-03-24 21:58:17 +01:00
|
|
|
QDBusConnection::sessionBus().registerService("org.mpris.clementine");
|
|
|
|
MPRIS mpris;
|
2010-03-24 22:07:16 +01:00
|
|
|
#endif
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Window
|
2010-04-15 14:39:34 +02:00
|
|
|
MainWindow w(&network, options.engine());
|
2010-01-17 17:10:26 +01:00
|
|
|
|
2010-04-14 23:27:27 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
mac::SetApplicationHandler(&w);
|
|
|
|
#endif
|
|
|
|
|
2010-04-13 00:44:29 +02: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();
|
|
|
|
}
|