2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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-12-29 18:53:28 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
2010-02-14 21:08:24 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
2011-01-15 21:51:48 +01:00
|
|
|
# define _WIN32_WINNT 0x0600
|
2010-02-14 21:08:24 +01:00
|
|
|
# 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"
|
2011-03-23 22:53:24 +01:00
|
|
|
#include "core/crashreporting.h"
|
2010-12-09 13:34:08 +01:00
|
|
|
#include "core/database.h"
|
2010-08-03 21:29:49 +02:00
|
|
|
#include "core/encoding.h"
|
2011-04-22 18:50:29 +02:00
|
|
|
#include "core/logging.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/mac_startup.h"
|
2010-10-16 19:20:54 +02:00
|
|
|
#include "core/network.h"
|
2010-12-25 18:25:29 +01:00
|
|
|
#include "core/networkproxyfactory.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/player.h"
|
|
|
|
#include "core/potranslator.h"
|
|
|
|
#include "core/song.h"
|
2011-01-04 12:33:22 +01:00
|
|
|
#include "core/taskmanager.h"
|
2011-06-18 21:08:09 +02:00
|
|
|
#include "core/ubuntuunityhack.h"
|
2010-12-09 13:34:08 +01:00
|
|
|
#include "core/utilities.h"
|
2011-05-21 14:19:35 +02:00
|
|
|
#include "covers/albumcoverfetcher.h"
|
2011-04-02 15:34:06 +02:00
|
|
|
#include "covers/artloader.h"
|
|
|
|
#include "covers/coverproviders.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "engines/enginebase.h"
|
|
|
|
#include "library/directory.h"
|
2010-12-22 11:45:14 +01:00
|
|
|
#include "playlist/playlist.h"
|
2011-01-04 12:33:22 +01:00
|
|
|
#include "playlist/playlistmanager.h"
|
|
|
|
#include "radio/radiomodel.h"
|
2010-11-20 21:30:21 +01:00
|
|
|
#include "smartplaylists/generator.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#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"
|
2011-01-04 12:33:22 +01:00
|
|
|
#include "ui/systemtrayicon.h"
|
2011-01-24 21:45:15 +01:00
|
|
|
#include "version.h"
|
2011-01-04 12:33:22 +01:00
|
|
|
#include "widgets/osd.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
#include "qtsingleapplication.h"
|
|
|
|
#include "qtsinglecoreapplication.h"
|
|
|
|
|
2010-12-09 13:34:08 +01:00
|
|
|
#include <QDir>
|
2010-02-23 19:33:09 +01:00
|
|
|
#include <QLibraryInfo>
|
2010-12-25 18:25:29 +01:00
|
|
|
#include <QNetworkProxyFactory>
|
2010-12-09 13:34:08 +01:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
2011-06-22 23:52:51 +02:00
|
|
|
#include <QTextCodec>
|
2010-02-23 19:33:09 +01:00
|
|
|
#include <QTranslator>
|
2010-12-09 13:34:08 +01:00
|
|
|
#include <QtDebug>
|
2010-03-24 22:34:32 +01:00
|
|
|
|
2010-07-20 11:25:20 +02:00
|
|
|
#include <glib-object.h>
|
2010-04-30 21:45:43 +02:00
|
|
|
#include <glib/gutils.h>
|
2010-12-26 14:01:35 +01:00
|
|
|
#include <gst/gst.h>
|
2010-04-30 21:45:43 +02:00
|
|
|
|
2011-01-04 12:33:22 +01:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
using boost::scoped_ptr;
|
|
|
|
|
2010-10-02 18:23:33 +02:00
|
|
|
#include <echonest/Config.h>
|
|
|
|
|
2010-12-21 16:48:30 +01:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
|
|
|
#include "radio/lastfmservice.h"
|
2011-02-13 19:36:29 +01:00
|
|
|
#else
|
|
|
|
class LastFMService;
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-01-04 12:33:22 +01:00
|
|
|
#ifdef HAVE_DBUS
|
|
|
|
#include "core/mpris.h"
|
|
|
|
#include "core/mpris2.h"
|
2011-01-11 21:36:16 +01:00
|
|
|
#include "dbus/metatypes.h"
|
2011-01-04 12:33:22 +01:00
|
|
|
#include <QDBusArgument>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QImage>
|
|
|
|
|
|
|
|
QDBusArgument& operator<< (QDBusArgument& arg, const QImage& image);
|
|
|
|
const QDBusArgument& operator>> (const QDBusArgument& arg, QImage& image);
|
|
|
|
#endif
|
|
|
|
|
2010-12-26 14:01:35 +01:00
|
|
|
class GstEnginePipeline;
|
2010-06-06 16:06:23 +02:00
|
|
|
|
2010-04-13 21:43:08 +02:00
|
|
|
// Load sqlite plugin on windows and mac.
|
2010-06-30 21:55:46 +02:00
|
|
|
#ifdef HAVE_STATIC_SQLITE
|
2010-03-22 19:35:31 +01:00
|
|
|
# include <QtPlugin>
|
|
|
|
Q_IMPORT_PLUGIN(qsqlite)
|
|
|
|
#endif
|
|
|
|
|
2010-08-02 21:02:21 +02:00
|
|
|
void LoadTranslation(const QString& prefix, const QString& path,
|
|
|
|
const QString& override_language = QString()) {
|
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-08-02 21:02:21 +02:00
|
|
|
QString language = override_language.isEmpty() ?
|
|
|
|
QLocale::system().name() : override_language;
|
|
|
|
|
2010-04-08 16:29:08 +02:00
|
|
|
QTranslator* t = new PoTranslator;
|
2010-08-02 21:02:21 +02:00
|
|
|
if (t->load(prefix + "_" + language, path))
|
2010-03-23 19:00:55 +01:00
|
|
|
QCoreApplication::installTranslator(t);
|
|
|
|
else
|
|
|
|
delete t;
|
2011-06-22 22:41:48 +02:00
|
|
|
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
|
2010-03-02 18:48:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-07 16:12:37 +02:00
|
|
|
#ifdef HAVE_REMOTE
|
2011-04-07 15:38:27 +02:00
|
|
|
#include <xrme/connection.h>
|
|
|
|
#include "remote/icesession.h"
|
2011-04-07 16:12:37 +02:00
|
|
|
#endif
|
2011-04-07 15:38:27 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2011-03-23 22:53:24 +01:00
|
|
|
if (CrashReporting::SendCrashReport(argc, argv)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporting crash_reporting;
|
|
|
|
|
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();
|
2010-12-21 16:48:30 +01:00
|
|
|
|
2010-12-30 14:03:36 +01:00
|
|
|
{
|
|
|
|
// Bump the soft limit for the number of file descriptors from the default of 256 to
|
|
|
|
// the maximum (usually 10240).
|
|
|
|
struct rlimit limit;
|
|
|
|
getrlimit(RLIMIT_NOFILE, &limit);
|
2010-12-21 16:48:30 +01:00
|
|
|
|
2010-12-30 14:03:36 +01:00
|
|
|
// getrlimit() lies about the hard limit so we have to check sysctl.
|
|
|
|
int max_fd = 0;
|
|
|
|
size_t len = sizeof(max_fd);
|
|
|
|
sysctlbyname("kern.maxfilesperproc", &max_fd, &len, NULL, 0);
|
2010-12-21 16:48:30 +01:00
|
|
|
|
2010-12-30 14:03:36 +01:00
|
|
|
limit.rlim_cur = max_fd;
|
|
|
|
int ret = setrlimit(RLIMIT_NOFILE, &limit);
|
2010-12-21 16:48:30 +01:00
|
|
|
|
2010-12-30 14:03:36 +01:00
|
|
|
if (ret == 0) {
|
2011-04-22 18:50:29 +02:00
|
|
|
qLog(Debug) << "Max fd:" << max_fd;
|
2010-12-30 14:03:36 +01:00
|
|
|
}
|
2010-12-21 16:48:30 +01:00
|
|
|
}
|
2010-04-13 15:55:54 +02:00
|
|
|
#endif
|
|
|
|
|
2010-01-08 17:21:22 +01:00
|
|
|
QCoreApplication::setApplicationName("Clementine");
|
2011-01-03 15:21:10 +01:00
|
|
|
QCoreApplication::setApplicationVersion(CLEMENTINE_VERSION_DISPLAY);
|
2010-01-08 17:21:22 +01:00
|
|
|
QCoreApplication::setOrganizationName("Clementine");
|
2011-02-16 14:43:01 +01:00
|
|
|
QCoreApplication::setOrganizationDomain("clementine-player.org");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-12-09 13:34:08 +01:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
// Must happen after QCoreApplication::setOrganizationName().
|
2011-02-16 14:58:45 +01:00
|
|
|
setenv("XDG_CONFIG_HOME", Utilities::GetConfigPath(Utilities::Path_Root).toLocal8Bit().constData(), 1);
|
2010-12-09 13:34:08 +01:00
|
|
|
if (mac::MigrateLegacyConfigFiles()) {
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
db.setDatabaseName(Utilities::GetConfigPath(
|
2010-12-09 14:06:00 +01:00
|
|
|
Utilities::Path_Root) + "/" + Database::kDatabaseFilename);
|
2010-12-09 13:34:08 +01:00
|
|
|
db.open();
|
|
|
|
QSqlQuery query(
|
|
|
|
"UPDATE songs SET art_manual = replace("
|
|
|
|
"art_manual, '.config', 'Library/Application Support') "
|
2010-12-09 14:06:00 +01:00
|
|
|
"WHERE art_manual LIKE '%.config%'", db);
|
2010-12-09 13:34:08 +01:00
|
|
|
query.exec();
|
|
|
|
db.close();
|
2010-12-09 14:06:00 +01:00
|
|
|
QSqlDatabase::removeDatabase(db.connectionName());
|
2010-12-09 13:34:08 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-30 21:45:43 +02:00
|
|
|
// This makes us show up nicely in gnome-volume-control
|
2010-07-20 11:25:20 +02:00
|
|
|
g_type_init();
|
2010-04-30 21:45:43 +02:00
|
|
|
g_set_application_name(QCoreApplication::applicationName().toLocal8Bit());
|
|
|
|
|
2011-05-21 14:19:35 +02:00
|
|
|
qRegisterMetaType<CoverSearchResult>("CoverSearchResult");
|
2011-05-22 16:10:54 +02:00
|
|
|
qRegisterMetaType<QList<CoverSearchResult> >("QList<CoverSearchResult>");
|
2011-05-29 16:08:55 +02:00
|
|
|
qRegisterMetaType<CoverSearchResults>("CoverSearchResults");
|
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");
|
2011-03-12 22:19:41 +01:00
|
|
|
qRegisterMetaType<Song>("Song");
|
2011-05-20 01:02:15 +02:00
|
|
|
qRegisterMetaType<QList<Song> >("QList<Song>");
|
2011-05-29 16:08:55 +02:00
|
|
|
qRegisterMetaType<SongList>("SongList");
|
2011-05-29 14:55:18 +02:00
|
|
|
qRegisterMetaType<PlaylistItemPtr>("PlaylistItemPtr");
|
|
|
|
qRegisterMetaType<QList<PlaylistItemPtr> >("QList<PlaylistItemPtr>");
|
2011-05-29 16:08:55 +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*");
|
2010-09-26 16:21:23 +02:00
|
|
|
qRegisterMetaType<QNetworkReply**>("QNetworkReply**");
|
2010-11-20 21:30:21 +01:00
|
|
|
qRegisterMetaType<smart_playlists::GeneratorPtr>("smart_playlists::GeneratorPtr");
|
2010-12-22 11:45:14 +01:00
|
|
|
qRegisterMetaType<ColumnAlignmentMap>("ColumnAlignmentMap");
|
|
|
|
qRegisterMetaTypeStreamOperators<QMap<int, int> >("ColumnAlignmentMap");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
qRegisterMetaType<GstBuffer*>("GstBuffer*");
|
2010-09-23 00:22:02 +02:00
|
|
|
qRegisterMetaType<GstElement*>("GstElement*");
|
2010-06-06 16:06:23 +02:00
|
|
|
qRegisterMetaType<GstEnginePipeline*>("GstEnginePipeline*");
|
|
|
|
|
2011-04-07 16:12:37 +02:00
|
|
|
#ifdef HAVE_REMOTE
|
2011-05-18 15:54:26 +02:00
|
|
|
qRegisterMetaType<xrme::SIPInfo>("xrme::SIPInfo");
|
2011-04-07 16:12:37 +02:00
|
|
|
#endif
|
2011-04-07 15:38:27 +02:00
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2010-02-23 20:26:21 +01:00
|
|
|
lastfm::ws::ApiKey = LastFMService::kApiKey;
|
|
|
|
lastfm::ws::SharedSecret = LastFMService::kSecret;
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
2010-02-23 20:26:21 +01:00
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
CommandlineOptions options(argc, argv);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Only start a core application now so we can check if there's another
|
|
|
|
// Clementine running without needing an X server.
|
2010-12-26 15:54:46 +01:00
|
|
|
// This MUST be done before parsing the commandline options so QTextCodec
|
|
|
|
// gets the right system locale for filenames.
|
2010-07-10 18:20:09 +02:00
|
|
|
QtSingleCoreApplication a(argc, argv);
|
2011-03-23 22:53:24 +01:00
|
|
|
crash_reporting.SetApplicationPath(a.applicationFilePath());
|
2010-12-26 15:54:46 +01:00
|
|
|
|
|
|
|
// Parse commandline options - need to do this before starting the
|
|
|
|
// full QApplication so it works without an X server
|
|
|
|
if (!options.Parse())
|
|
|
|
return 1;
|
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
if (a.isRunning()) {
|
|
|
|
if (options.is_empty()) {
|
2011-04-22 18:50:29 +02:00
|
|
|
qLog(Info) << "Clementine is already running - activating existing window";
|
2010-07-10 18:20:09 +02:00
|
|
|
}
|
|
|
|
if (a.sendMessage(options.Serialize(), 5000)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Couldn't send the message so start anyway
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2011-04-07 16:12:37 +02:00
|
|
|
#ifdef HAVE_REMOTE
|
2011-04-07 15:38:27 +02:00
|
|
|
if (options.stun_test() != CommandlineOptions::StunTestNone) {
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
ICESession::StaticInit();
|
|
|
|
ICESession ice;
|
2011-05-18 15:54:26 +02:00
|
|
|
ice.Init(options.stun_test() == CommandlineOptions::StunTestOffer
|
|
|
|
? ICESession::DirectionControlling
|
|
|
|
: ICESession::DirectionControlled);
|
2011-04-07 15:38:27 +02:00
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
QObject::connect(&ice,
|
2011-05-18 15:54:26 +02:00
|
|
|
SIGNAL(CandidatesAvailable(const xrme::SIPInfo&)),
|
2011-04-07 15:38:27 +02:00
|
|
|
&loop, SLOT(quit()));
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
const xrme::SIPInfo& candidates = ice.candidates();
|
|
|
|
qDebug() << candidates;
|
|
|
|
|
2011-05-18 15:54:26 +02:00
|
|
|
QString sip_info;
|
|
|
|
{
|
|
|
|
QFile file;
|
|
|
|
file.open(stdin, QIODevice::ReadOnly);
|
|
|
|
QTextStream in(&file);
|
|
|
|
in >> sip_info;
|
|
|
|
}
|
|
|
|
QStringList sip_components = sip_info.split(':');
|
2011-04-07 15:38:27 +02:00
|
|
|
|
|
|
|
xrme::SIPInfo remote_session;
|
2011-05-18 15:54:26 +02:00
|
|
|
remote_session.user_fragment = sip_components[0];
|
|
|
|
remote_session.password = sip_components[1];
|
2011-04-07 15:38:27 +02:00
|
|
|
|
|
|
|
xrme::SIPInfo::Candidate cand;
|
2011-05-18 15:54:26 +02:00
|
|
|
cand.address = sip_components[2];
|
|
|
|
cand.port = sip_components[3].toUShort();
|
|
|
|
cand.type = sip_components[4];
|
|
|
|
cand.component = sip_components[5].toInt();
|
|
|
|
cand.priority = sip_components[6].toInt();
|
|
|
|
cand.foundation = sip_components[7];
|
2011-04-07 15:38:27 +02:00
|
|
|
|
|
|
|
remote_session.candidates << cand;
|
|
|
|
|
|
|
|
qDebug() << "Remote:" << remote_session;
|
|
|
|
|
|
|
|
ice.StartNegotiation(remote_session);
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-07 16:12:37 +02:00
|
|
|
#endif
|
2011-04-07 15:38:27 +02:00
|
|
|
|
2011-04-22 18:50:29 +02:00
|
|
|
// Initialise logging
|
|
|
|
logging::Init();
|
|
|
|
logging::SetLevels(options.log_levels());
|
2011-04-25 21:16:26 +02:00
|
|
|
g_log_set_default_handler(reinterpret_cast<GLogFunc>(&logging::GLog), NULL);
|
2011-04-22 18:50:29 +02:00
|
|
|
|
2010-01-17 17:10:26 +01:00
|
|
|
QtSingleApplication a(argc, argv);
|
2010-07-11 22:14:25 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
2010-08-28 21:34:03 +02:00
|
|
|
QCoreApplication::setLibraryPaths(
|
|
|
|
QStringList() << QCoreApplication::applicationDirPath() + "/../PlugIns");
|
2010-07-11 22:14:25 +02:00
|
|
|
#endif
|
|
|
|
|
2010-04-07 18:26:04 +02:00
|
|
|
a.setQuitOnLastWindowClosed(false);
|
2010-12-25 18:49:04 +01:00
|
|
|
|
|
|
|
// Do this check again because another instance might have started by now
|
|
|
|
if (a.isRunning() && a.sendMessage(options.Serialize(), 5000)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-17 17:10:26 +01:00
|
|
|
|
2010-08-26 14:25:31 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
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-08-26 14:25:31 +02:00
|
|
|
#else
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, true);
|
|
|
|
#endif
|
2010-05-01 15:40:21 +02:00
|
|
|
|
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-08-02 21:02:21 +02:00
|
|
|
// Has the user forced a different language?
|
|
|
|
QString language = options.language();
|
|
|
|
if (language.isEmpty()) {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("General");
|
|
|
|
language = s.value("language").toString();
|
|
|
|
}
|
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Translations
|
2010-08-02 21:02:21 +02:00
|
|
|
LoadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath), language);
|
|
|
|
LoadTranslation("clementine", ":/translations", language);
|
|
|
|
LoadTranslation("clementine", a.applicationDirPath(), language);
|
|
|
|
LoadTranslation("clementine", QDir::currentPath(), language);
|
2010-03-02 18:29:43 +01:00
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
|
|
|
IconLoader::Init();
|
|
|
|
|
2010-10-02 18:23:33 +02:00
|
|
|
Echonest::Config::instance()->setAPIKey("DFLFLJBUF4EGTXHIG");
|
2010-10-16 19:20:54 +02:00
|
|
|
Echonest::Config::instance()->setNetworkAccessManager(new NetworkAccessManager);
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-12-25 18:25:29 +01:00
|
|
|
// Network proxy
|
|
|
|
QNetworkProxyFactory::setApplicationProxyFactory(
|
|
|
|
NetworkProxyFactory::Instance());
|
|
|
|
|
2010-08-29 14:34:07 +02:00
|
|
|
// Seed the random number generator
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2011-02-13 19:36:29 +01:00
|
|
|
// Create some key objects
|
2011-01-04 12:33:22 +01:00
|
|
|
scoped_ptr<BackgroundThread<Database> > database(
|
|
|
|
new BackgroundThreadImplementation<Database, Database>(NULL));
|
|
|
|
database->Start(true);
|
|
|
|
TaskManager task_manager;
|
|
|
|
PlaylistManager playlists(&task_manager, NULL);
|
2011-04-28 17:10:28 +02:00
|
|
|
Player player(&playlists);
|
|
|
|
RadioModel radio_model(database.get(), &task_manager, &player, NULL);
|
2011-02-13 19:36:29 +01:00
|
|
|
|
2011-04-02 15:34:06 +02:00
|
|
|
// Initialize the repository of cover providers to avoid race conditions
|
|
|
|
// later
|
|
|
|
CoverProviders::instance();
|
|
|
|
|
2011-06-22 22:52:49 +02:00
|
|
|
#ifdef Q_OS_LINUX
|
2011-06-18 21:08:09 +02:00
|
|
|
// In 11.04 Ubuntu decided that the system tray should be reserved for certain
|
|
|
|
// whitelisted applications. Clementine will override this setting and insert
|
|
|
|
// itself into the list of whitelisted apps.
|
|
|
|
UbuntuUnityHack hack;
|
2011-06-22 22:52:49 +02:00
|
|
|
#endif // Q_OS_LINUX
|
2011-06-18 21:08:09 +02:00
|
|
|
|
2011-02-13 19:36:29 +01:00
|
|
|
// Create the tray icon and OSD
|
2011-01-04 12:33:22 +01:00
|
|
|
scoped_ptr<SystemTrayIcon> tray_icon(SystemTrayIcon::CreateSystemTrayIcon());
|
|
|
|
OSD osd(tray_icon.get());
|
|
|
|
|
2011-02-19 19:24:11 +01:00
|
|
|
ArtLoader art_loader;
|
|
|
|
|
2011-01-04 12:33:22 +01:00
|
|
|
#ifdef HAVE_DBUS
|
|
|
|
qDBusRegisterMetaType<QImage>();
|
|
|
|
qDBusRegisterMetaType<TrackMetadata>();
|
|
|
|
qDBusRegisterMetaType<TrackIds>();
|
2011-01-11 21:36:16 +01:00
|
|
|
qDBusRegisterMetaType<QList<QByteArray> >();
|
2011-01-04 12:33:22 +01:00
|
|
|
|
2011-01-08 16:31:14 +01:00
|
|
|
mpris::Mpris mpris(&player, &art_loader);
|
2011-01-04 12:33:22 +01:00
|
|
|
|
|
|
|
QObject::connect(&playlists, SIGNAL(CurrentSongChanged(Song)), &art_loader, SLOT(LoadArt(Song)));
|
2011-02-19 19:24:11 +01:00
|
|
|
QObject::connect(&art_loader, SIGNAL(ThumbnailLoaded(Song, QString, QImage)),
|
2011-01-04 12:33:22 +01:00
|
|
|
&osd, SLOT(CoverArtPathReady(Song, QString)));
|
|
|
|
#endif
|
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Window
|
2011-01-04 12:33:22 +01:00
|
|
|
MainWindow w(
|
|
|
|
database.get(),
|
|
|
|
&task_manager,
|
|
|
|
&playlists,
|
|
|
|
&radio_model,
|
|
|
|
&player,
|
|
|
|
tray_icon.get(),
|
2011-02-19 19:24:11 +01:00
|
|
|
&osd,
|
|
|
|
&art_loader);
|
2011-01-04 12:33:22 +01:00
|
|
|
#ifdef HAVE_DBUS
|
2011-01-08 16:31:14 +01:00
|
|
|
QObject::connect(&mpris, SIGNAL(RaiseMainWindow()), &w, SLOT(Raise()));
|
2011-01-04 12:33:22 +01:00
|
|
|
#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
|
|
|
|
2010-12-30 17:20:33 +01:00
|
|
|
return a.exec();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|