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/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2010-12-29 18:53:28 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
2010-02-14 21:08:24 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
2014-02-07 16:34:20 +01:00
|
|
|
#define _WIN32_WINNT 0x0600
|
|
|
|
#include <windows.h>
|
|
|
|
#include <iostream>
|
2014-02-07 13:40:32 +01:00
|
|
|
#endif // Q_OS_WIN32
|
|
|
|
|
|
|
|
#ifdef Q_OS_UNIX
|
2014-02-07 16:34:20 +01:00
|
|
|
#include <unistd.h>
|
2014-02-07 13:40:32 +01:00
|
|
|
#endif // Q_OS_UNIX
|
2010-02-14 21:08:24 +01:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QNetworkProxyFactory>
|
|
|
|
#include <QSslSocket>
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QSysInfo>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2010-05-03 15:58:41 +02:00
|
|
|
#include "config.h"
|
2012-02-12 14:41:50 +01:00
|
|
|
#include "core/application.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"
|
2012-02-27 02:58:15 +01:00
|
|
|
#include "core/database.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"
|
2012-06-20 15:07:28 +02:00
|
|
|
#include "core/metatypes.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/potranslator.h"
|
|
|
|
#include "core/song.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-07-23 20:34:54 +02:00
|
|
|
#include "covers/amazoncoverprovider.h"
|
2011-04-02 15:34:06 +02:00
|
|
|
#include "covers/coverproviders.h"
|
2012-10-10 14:45:13 +02:00
|
|
|
#include "covers/discogscoverprovider.h"
|
|
|
|
#include "covers/musicbrainzcoverprovider.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "engines/enginebase.h"
|
2010-11-20 21:30:21 +01:00
|
|
|
#include "smartplaylists/generator.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
|
|
|
|
2012-11-11 09:54:43 +01:00
|
|
|
#include "tagreadermessages.pb.h"
|
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
#include "qtsingleapplication.h"
|
|
|
|
#include "qtsinglecoreapplication.h"
|
|
|
|
|
2010-07-20 11:25:20 +02:00
|
|
|
#include <glib-object.h>
|
2011-10-26 12:14:02 +02:00
|
|
|
#include <glib.h>
|
2010-12-26 14:01:35 +01:00
|
|
|
#include <gst/gst.h>
|
2010-04-30 21:45:43 +02:00
|
|
|
|
2010-10-02 18:23:33 +02:00
|
|
|
#include <echonest/Config.h>
|
|
|
|
|
2013-09-17 17:09:56 +02:00
|
|
|
#ifdef HAVE_SPOTIFY_DOWNLOADER
|
2014-02-07 16:34:20 +01:00
|
|
|
#include <QtCrypto>
|
2013-09-17 17:09:56 +02:00
|
|
|
#endif
|
2011-11-05 02:12:28 +01:00
|
|
|
|
2010-12-21 16:48:30 +01:00
|
|
|
#ifdef Q_OS_DARWIN
|
2014-02-07 16:34:20 +01:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/sysctl.h>
|
2010-12-21 16:48:30 +01:00
|
|
|
#endif
|
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2014-02-07 16:34:20 +01:00
|
|
|
#include "internet/lastfmservice.h"
|
2011-02-13 19:36:29 +01:00
|
|
|
#else
|
2014-02-07 16:34:20 +01:00
|
|
|
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
|
2014-02-07 16:34:20 +01:00
|
|
|
#include "core/mpris.h"
|
|
|
|
#include "core/mpris2.h"
|
|
|
|
#include <QDBusArgument>
|
|
|
|
#include <QImage>
|
2011-01-04 12:33:22 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image);
|
|
|
|
const QDBusArgument& operator>>(const QDBusArgument& arg, QImage& image);
|
2011-01-04 12:33:22 +01:00
|
|
|
#endif
|
|
|
|
|
2012-08-08 20:16:23 +02:00
|
|
|
#ifdef Q_OS_WIN32
|
2014-02-07 16:34:20 +01:00
|
|
|
#include <qtsparkle/Updater>
|
2012-08-08 20:16:23 +02:00
|
|
|
#endif
|
|
|
|
|
2010-04-13 21:43:08 +02:00
|
|
|
// Load sqlite plugin on windows and mac.
|
2013-11-22 17:05:55 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
Q_IMPORT_PLUGIN(qsqlite)
|
2010-03-22 19:35:31 +01:00
|
|
|
|
2014-02-13 18:59:59 +01:00
|
|
|
namespace {
|
|
|
|
|
2010-08-02 21:02:21 +02:00
|
|
|
void LoadTranslation(const QString& prefix, const QString& path,
|
2013-07-27 07:27:08 +02:00
|
|
|
const QString& language) {
|
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");
|
2014-02-07 16:34:20 +01:00
|
|
|
if (maybe_clementine_directory.exists() &&
|
|
|
|
!maybe_clementine_directory.isFile())
|
2010-03-23 19:00:55 +01:00
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2012-01-04 15:08:31 +01:00
|
|
|
void IncreaseFDLimit() {
|
|
|
|
#ifdef Q_OS_DARWIN
|
2014-02-07 16:34:20 +01:00
|
|
|
// Bump the soft limit for the number of file descriptors from the default of
|
|
|
|
// 256 to
|
2012-01-04 15:08:31 +01:00
|
|
|
// the maximum (usually 10240).
|
|
|
|
struct rlimit limit;
|
|
|
|
getrlimit(RLIMIT_NOFILE, &limit);
|
|
|
|
|
|
|
|
// getrlimit() lies about the hard limit so we have to check sysctl.
|
|
|
|
int max_fd = 0;
|
|
|
|
size_t len = sizeof(max_fd);
|
2014-02-06 16:49:49 +01:00
|
|
|
sysctlbyname("kern.maxfilesperproc", &max_fd, &len, nullptr, 0);
|
2012-01-04 15:08:31 +01:00
|
|
|
|
|
|
|
limit.rlim_cur = max_fd;
|
|
|
|
int ret = setrlimit(RLIMIT_NOFILE, &limit);
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
qLog(Debug) << "Max fd:" << max_fd;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SetEnv(const char* key, const QString& value) {
|
2012-06-20 11:19:34 +02:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
putenv(QString("%1=%2").arg(key, value).toLocal8Bit().constData());
|
|
|
|
#else
|
|
|
|
setenv(key, value.toLocal8Bit().constData(), 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// This must be done early so that the spotify blob process also picks up
|
|
|
|
// these environment variables.
|
|
|
|
void SetGstreamerEnvironment() {
|
|
|
|
QString scanner_path;
|
|
|
|
QString plugin_path;
|
|
|
|
QString registry_filename;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// On windows and mac we bundle the gstreamer plugins with clementine
|
2012-06-20 11:19:34 +02:00
|
|
|
#if defined(Q_OS_DARWIN)
|
2014-02-07 16:34:20 +01:00
|
|
|
scanner_path =
|
|
|
|
QCoreApplication::applicationDirPath() + "/../PlugIns/gst-plugin-scanner";
|
|
|
|
plugin_path =
|
|
|
|
QCoreApplication::applicationDirPath() + "/../PlugIns/gstreamer";
|
2012-06-20 11:19:34 +02:00
|
|
|
#elif defined(Q_OS_WIN32)
|
|
|
|
plugin_path = QCoreApplication::applicationDirPath() + "/gstreamer-plugins";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_DARWIN)
|
2014-02-07 16:34:20 +01:00
|
|
|
registry_filename =
|
|
|
|
Utilities::GetConfigPath(Utilities::Path_GstreamerRegistry);
|
2012-06-20 11:19:34 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!scanner_path.isEmpty()) SetEnv("GST_PLUGIN_SCANNER", scanner_path);
|
2012-06-20 11:19:34 +02:00
|
|
|
|
|
|
|
if (!plugin_path.isEmpty()) {
|
|
|
|
SetEnv("GST_PLUGIN_PATH", plugin_path);
|
|
|
|
// Never load plugins from anywhere else.
|
|
|
|
SetEnv("GST_PLUGIN_SYSTEM_PATH", plugin_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!registry_filename.isEmpty()) {
|
|
|
|
SetEnv("GST_REGISTRY", registry_filename);
|
|
|
|
}
|
2012-07-30 17:51:45 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
SetEnv("GIO_EXTRA_MODULES",
|
2014-02-07 16:34:20 +01:00
|
|
|
QCoreApplication::applicationDirPath() + "/../PlugIns/gio-modules");
|
2012-07-30 17:51:45 +02:00
|
|
|
#endif
|
2014-06-19 14:51:58 +02:00
|
|
|
|
|
|
|
SetEnv("PULSE_PROP_media.role", "music");
|
2012-06-20 11:19:34 +02:00
|
|
|
}
|
|
|
|
|
2012-11-11 09:54:43 +01:00
|
|
|
void ParseAProto() {
|
|
|
|
const QByteArray data = QByteArray::fromHex(
|
2014-02-07 16:34:20 +01:00
|
|
|
"08001a8b010a8801b2014566696c653a2f2f2f453a2f4d7573696b2f28414c42554d2"
|
|
|
|
"9253230476f74616e25323050726f6a6563742532302d253230416d6269656e742532"
|
|
|
|
"304c6f756e67652e6d786dba012a28414c42554d2920476f74616e2050726f6a65637"
|
|
|
|
"4202d20416d6269656e74204c6f756e67652e6d786dc001c7a7efd104c801bad685e4"
|
|
|
|
"04d001eeca32");
|
2012-11-11 09:54:43 +01:00
|
|
|
pb::tagreader::Message message;
|
|
|
|
message.ParseFromArray(data.constData(), data.size());
|
|
|
|
}
|
|
|
|
|
2013-09-29 10:43:34 +02:00
|
|
|
void CheckPortable() {
|
|
|
|
QFile f(QApplication::applicationDirPath() + QDir::separator() + "data");
|
|
|
|
if (f.exists()) {
|
|
|
|
// We are portable. Set the bool and change the qsettings path
|
|
|
|
Application::kIsPortable = true;
|
|
|
|
|
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
2014-02-07 16:34:20 +01:00
|
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope,
|
|
|
|
f.fileName());
|
2013-09-29 10:43:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:59:59 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#ifdef HAVE_GIO
|
|
|
|
#undef signals // Clashes with GIO, and not needed in this file
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void ScanGIOModulePath() {
|
|
|
|
QString gio_module_path;
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
gio_module_path = QCoreApplication::applicationDirPath() + "/gio-modules";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!gio_module_path.isEmpty()) {
|
|
|
|
qLog(Debug) << "Adding GIO module path:" << gio_module_path;
|
|
|
|
QByteArray bytes = gio_module_path.toLocal8Bit();
|
|
|
|
g_io_modules_scan_all_in_directory(bytes.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
#endif // HAVE_GIO
|
|
|
|
|
2014-02-07 16:34:20 +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();
|
2013-10-28 17:12:23 +01:00
|
|
|
|
2013-10-28 17:39:18 +01:00
|
|
|
if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
|
2013-10-28 17:12:23 +01:00
|
|
|
// Work around 10.9 issue.
|
|
|
|
// https://bugreports.qt-project.org/browse/QTBUG-32789
|
|
|
|
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
|
|
|
|
}
|
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
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// This makes us show up nicely in gnome-volume-control
|
2013-10-30 22:36:44 +01:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
|
g_type_init(); // Deprecated in glib 2.36.0
|
|
|
|
#endif
|
|
|
|
g_set_application_name(QCoreApplication::applicationName().toLocal8Bit());
|
|
|
|
|
|
|
|
RegisterMetaTypes();
|
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
CommandlineOptions options(argc, argv);
|
|
|
|
|
2014-03-12 19:06:00 +01:00
|
|
|
// Initialise logging
|
|
|
|
logging::Init();
|
|
|
|
logging::SetLevels(options.log_levels());
|
|
|
|
g_log_set_default_handler(reinterpret_cast<GLogFunc>(&logging::GLog),
|
|
|
|
nullptr);
|
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
{
|
|
|
|
// 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);
|
2013-10-10 18:36:12 +02:00
|
|
|
CheckPortable();
|
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
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!options.Parse()) return 1;
|
2010-12-26 15:54:46 +01:00
|
|
|
|
2010-07-10 18:20:09 +02:00
|
|
|
if (a.isRunning()) {
|
|
|
|
if (options.is_empty()) {
|
2014-02-07 16:34:20 +01: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 18:36:12 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
// Must happen after QCoreApplication::setOrganizationName().
|
2014-02-07 16:34:20 +01:00
|
|
|
setenv(
|
|
|
|
"XDG_CONFIG_HOME",
|
|
|
|
Utilities::GetConfigPath(Utilities::Path_Root).toLocal8Bit().constData(),
|
|
|
|
1);
|
2013-10-10 18:36:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBLASTFM
|
|
|
|
lastfm::ws::ApiKey = LastFMService::kApiKey;
|
|
|
|
lastfm::ws::SharedSecret = LastFMService::kSecret;
|
|
|
|
lastfm::setNetworkAccessManager(new NetworkAccessManager);
|
|
|
|
#endif
|
|
|
|
|
2012-12-26 02:37:57 +01:00
|
|
|
// Output the version, so when people attach log output to bug reports they
|
|
|
|
// don't have to tell us which version they're using.
|
|
|
|
qLog(Info) << "Clementine" << CLEMENTINE_VERSION_DISPLAY;
|
|
|
|
|
2012-04-13 15:53:17 +02:00
|
|
|
// Seed the random number generators.
|
2014-02-06 16:49:49 +01:00
|
|
|
time_t t = time(nullptr);
|
2012-04-13 15:53:17 +02:00
|
|
|
srand(t);
|
2012-04-13 15:49:29 +02:00
|
|
|
qsrand(t);
|
|
|
|
|
2012-01-04 15:08:31 +01:00
|
|
|
IncreaseFDLimit();
|
|
|
|
|
2010-01-17 17:10:26 +01:00
|
|
|
QtSingleApplication a(argc, argv);
|
2012-05-13 18:41:38 +02:00
|
|
|
|
|
|
|
// A bug in Qt means the wheel_scroll_lines setting gets ignored and replaced
|
|
|
|
// with the default value of 3 in QApplicationPrivate::initialize.
|
|
|
|
{
|
|
|
|
QSettings qt_settings(QSettings::UserScope, "Trolltech");
|
|
|
|
qt_settings.beginGroup("Qt");
|
|
|
|
QApplication::setWheelScrollLines(
|
2014-02-07 16:34:20 +01:00
|
|
|
qt_settings.value("wheelScrollLines", QApplication::wheelScrollLines())
|
|
|
|
.toInt());
|
2012-05-13 18:41:38 +02:00
|
|
|
}
|
|
|
|
|
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);
|
2012-06-13 15:50:58 +02:00
|
|
|
// Fixes focus issue with NSSearchField, see QTBUG-11401
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_NativeWindows, true);
|
2010-08-26 14:25:31 +02:00
|
|
|
#endif
|
2010-05-01 15:40:21 +02:00
|
|
|
|
2012-06-20 11:19:34 +02:00
|
|
|
SetGstreamerEnvironment();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Set the permissions on the config file on Unix - it can contain passwords
|
|
|
|
// for internet services so it's important that other users can't read it.
|
|
|
|
// On Windows these are stored in the registry instead.
|
2011-10-01 18:15:12 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
// Create the file if it doesn't exist already
|
|
|
|
if (!QFile::exists(s.fileName())) {
|
|
|
|
QFile file(s.fileName());
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set -rw-------
|
|
|
|
QFile::setPermissions(s.fileName(), QFile::ReadOwner | QFile::WriteOwner);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-17 17:09:56 +02:00
|
|
|
#ifdef HAVE_SPOTIFY_DOWNLOADER
|
2011-11-05 02:12:28 +01:00
|
|
|
QCA::Initializer qca_initializer;
|
2013-09-17 17:09:56 +02:00
|
|
|
#endif
|
2011-11-05 02:12:28 +01: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
|
|
|
|
2012-01-09 23:53:17 +01:00
|
|
|
// Grooveshark uses GoDaddy to sign its SSL certificates, which are in turn
|
|
|
|
// signed by a ValiCert CA. This CA certificate isn't installed by default
|
|
|
|
// in Windows, it's only added by windows update, or manually browsing to a
|
|
|
|
// website with a certificate signed by ValiCert. Here we explicitly add
|
|
|
|
// that CA to the default list used by QSslSocket, so it always works in
|
|
|
|
// Clementine.
|
|
|
|
QSslSocket::addDefaultCaCertificates(
|
2014-02-07 16:34:20 +01:00
|
|
|
QSslCertificate::fromPath(":/grooveshark-valicert-ca.pem", QSsl::Pem));
|
2012-01-09 23:53:17 +01:00
|
|
|
|
2010-08-02 21:02:21 +02:00
|
|
|
// Has the user forced a different language?
|
2013-07-27 07:27:08 +02:00
|
|
|
QString override_language = options.language();
|
|
|
|
if (override_language.isEmpty()) {
|
2010-08-02 21:02:21 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("General");
|
2013-07-27 07:27:08 +02:00
|
|
|
override_language = s.value("language").toString();
|
2010-08-02 21:02:21 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QString language = override_language.isEmpty()
|
|
|
|
? Utilities::SystemLanguageName()
|
|
|
|
: override_language;
|
2013-07-27 07:27:08 +02:00
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Translations
|
2014-02-07 16:34:20 +01:00
|
|
|
LoadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath),
|
|
|
|
language);
|
2010-08-02 21:02:21 +02:00
|
|
|
LoadTranslation("clementine", ":/translations", language);
|
|
|
|
LoadTranslation("clementine", a.applicationDirPath(), language);
|
|
|
|
LoadTranslation("clementine", QDir::currentPath(), language);
|
2010-03-02 18:29:43 +01:00
|
|
|
|
2012-08-08 20:16:23 +02:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
// Set the language for qtsparkle
|
|
|
|
qtsparkle::LoadTranslations(language);
|
|
|
|
#endif
|
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
|
|
|
IconLoader::Init();
|
|
|
|
|
2012-11-11 09:54:43 +01:00
|
|
|
// This is a nasty hack to ensure that everything in libprotobuf is
|
|
|
|
// initialised in the main thread. It fixes issue 3265 but nobody knows why.
|
|
|
|
// Don't remove this unless you can reproduce the error that it fixes.
|
|
|
|
ParseAProto();
|
|
|
|
QtConcurrent::run(&ParseAProto);
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application app;
|
2013-07-27 07:27:08 +02:00
|
|
|
app.set_language_name(language);
|
2012-01-09 20:08:09 +01:00
|
|
|
|
2010-10-02 18:23:33 +02:00
|
|
|
Echonest::Config::instance()->setAPIKey("DFLFLJBUF4EGTXHIG");
|
2014-02-07 16:34:20 +01: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());
|
|
|
|
|
2011-07-23 20:34:41 +02:00
|
|
|
// Initialize the repository of cover providers. Last.fm registers itself
|
|
|
|
// when its service is created.
|
2012-02-12 14:41:50 +01:00
|
|
|
app.cover_providers()->AddProvider(new AmazonCoverProvider);
|
|
|
|
app.cover_providers()->AddProvider(new DiscogsCoverProvider);
|
2012-10-10 14:45:13 +02:00
|
|
|
app.cover_providers()->AddProvider(new MusicbrainzCoverProvider);
|
2011-04-02 15:34:06 +02:00
|
|
|
|
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;
|
2014-02-07 16:34:20 +01: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
|
2014-02-07 16:34:20 +01:00
|
|
|
std::unique_ptr<SystemTrayIcon> tray_icon(
|
|
|
|
SystemTrayIcon::CreateSystemTrayIcon());
|
2012-02-12 14:41:50 +01:00
|
|
|
OSD osd(tray_icon.get(), &app);
|
2011-01-04 12:33:22 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_DBUS
|
2012-02-13 21:44:04 +01:00
|
|
|
mpris::Mpris mpris(&app);
|
2011-01-04 12:33:22 +01:00
|
|
|
#endif
|
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
// Window
|
2012-02-13 21:44:04 +01:00
|
|
|
MainWindow w(&app, tray_icon.get(), &osd);
|
2012-10-09 14:56:17 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
mac::EnableFullScreen(w);
|
|
|
|
#endif // Q_OS_DARWIN
|
2012-02-01 18:37:10 +01:00
|
|
|
#ifdef HAVE_GIO
|
|
|
|
ScanGIOModulePath();
|
|
|
|
#endif
|
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
|
2014-02-07 16:34:20 +01:00
|
|
|
QObject::connect(&a, SIGNAL(messageReceived(QByteArray)), &w,
|
|
|
|
SLOT(CommandlineOptionsReceived(QByteArray)));
|
2010-04-13 00:44:29 +02:00
|
|
|
w.CommandlineOptionsReceived(options);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-10-23 16:43:41 +02:00
|
|
|
int ret = a.exec();
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
// The nvidia driver would cause Clementine (or any application that used
|
|
|
|
// opengl) to use 100% cpu on shutdown. See:
|
|
|
|
// http://code.google.com/p/clementine-player/issues/detail?id=2088
|
|
|
|
// https://bugs.gentoo.org/show_bug.cgi?id=375615
|
|
|
|
// Work around this problem by exiting immediately (and not running the buggy
|
|
|
|
// nvidia atexit shutdown handler) if we're using one of the affected versions
|
|
|
|
// of the nvidia driver.
|
|
|
|
|
|
|
|
QFile self_maps("/proc/self/maps");
|
|
|
|
if (self_maps.open(QIODevice::ReadOnly)) {
|
|
|
|
QByteArray data = self_maps.readAll();
|
2012-09-24 20:54:46 +02:00
|
|
|
if (data.contains("libnvidia-tls.so.")) {
|
2011-10-23 16:43:41 +02:00
|
|
|
qLog(Warning) << "Exiting immediately to work around NVIDIA driver bug";
|
|
|
|
_exit(ret);
|
|
|
|
}
|
|
|
|
self_maps.close();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|