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

96 lines
2.8 KiB
C++

/* 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
#include "directory.h"
#include "lastfmservice.h"
#include "mainwindow.h"
#include "song.h"
#include <QtSingleApplication>
#include <QtDebug>
#include <QLibraryInfo>
#include <QTranslator>
#include <QDir>
#include <QNetworkAccessManager>
// Load sqlite plugin on windows
#ifdef WIN32
# include <QtPlugin>
Q_IMPORT_PLUGIN(qsqlite)
#endif
void LoadTranslation(const QString& prefix, const QString& path) {
// QTranslator::load will try to open and read "clementine" if it exists,
// without checking if it's a file first.
QFileInfo maybe_clementine_directory(path + "/clementine");
if (maybe_clementine_directory.exists() && !maybe_clementine_directory.isFile())
return;
QTranslator* t = new QTranslator;
if (t->load(prefix + "_" + QLocale::system().name(), path))
QCoreApplication::installTranslator(t);
else
delete t;
}
int main(int argc, char *argv[]) {
QCoreApplication::setApplicationName("Clementine");
QCoreApplication::setApplicationVersion("0.2");
QCoreApplication::setOrganizationName("Clementine");
QCoreApplication::setOrganizationDomain("davidsansome.com");
qRegisterMetaType<DirectoryList>("DirectoryList");
qRegisterMetaType<SongList>("SongList");
lastfm::ws::ApiKey = LastFMService::kApiKey;
lastfm::ws::SharedSecret = LastFMService::kSecret;
QtSingleApplication a(argc, argv);
if (a.isRunning()) {
qDebug() << "Clementine is already running - activating existing window";
if (a.sendMessage("wake up!"))
return 0;
// Couldn't send the message so start anyway
}
// Resources
Q_INIT_RESOURCE(data);
Q_INIT_RESOURCE(translations);
// Translations
LoadTranslation("qt", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
LoadTranslation("clementine", ":/translations");
LoadTranslation("clementine", a.applicationDirPath());
LoadTranslation("clementine", QDir::currentPath());
QNetworkAccessManager network;
// Window
MainWindow w(&network);;
a.setActivationWindow(&w);
QObject::connect(&a, SIGNAL(messageReceived(QString)), &w, SLOT(show()));
return a.exec();
}