2006-09-30 20:02:39 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QSplashScreen>
|
|
|
|
#include <QTcpSocket>
|
2006-11-14 23:26:32 +03:00
|
|
|
#include <QSettings>
|
2006-09-30 20:02:39 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "GUI.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
// Main
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
QFile file;
|
|
|
|
QString locale;
|
|
|
|
if(argc > 1){
|
|
|
|
if(QString(argv[1])=="--version"){
|
|
|
|
std::cout << "qBittorrent " << VERSION << '\n';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(QString(argv[1])=="--help"){
|
|
|
|
std::cout << "Usage: \n";
|
|
|
|
std::cout << '\t' << argv[0] << " --version : displays program version\n";
|
|
|
|
std::cout << '\t' << argv[0] << " --help : displays this help message\n";
|
|
|
|
std::cout << '\t' << argv[0] << " [files or urls] : starts program and download given parameters (optional)\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Set environment variable
|
|
|
|
if(putenv("QBITTORRENT="VERSION)){
|
2006-10-16 13:02:53 +04:00
|
|
|
std::cerr << "Couldn't set environment variable...\n";
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
//Check if there is another instance running
|
|
|
|
QTcpSocket tcpSocket;
|
|
|
|
tcpSocket.connectToHost(QHostAddress::LocalHost, 1666);
|
|
|
|
if (tcpSocket.waitForConnected(1000)){
|
2006-12-05 03:27:00 +03:00
|
|
|
std::cout << "Another qBittorrent instance is already running...\n";
|
|
|
|
// Send parameters
|
|
|
|
if(argc > 1){
|
|
|
|
QStringList params;
|
|
|
|
for(int i=1;i<argc;++i){
|
|
|
|
params << QString(argv[i]);
|
|
|
|
std::cout << QString(argv[i]).toStdString() << '\n';
|
|
|
|
}
|
|
|
|
QByteArray block = params.join("\n").toUtf8();
|
|
|
|
std::cout << "writting: " << block.data() << '\n';
|
|
|
|
std::cout << "size: " << block.size() << '\n';
|
|
|
|
uint val = tcpSocket.write(block);
|
|
|
|
if(tcpSocket.waitForBytesWritten(5000)){
|
|
|
|
std::cout << "written(" <<val<<"): " << block.data() << '\n';
|
|
|
|
}else{
|
|
|
|
std::cerr << "Writing to the socket timed out\n";
|
|
|
|
}
|
|
|
|
tcpSocket.disconnectFromHost();
|
|
|
|
std::cout << "disconnected\n";
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
tcpSocket.close();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
QSplashScreen *splash = new QSplashScreen(QPixmap(":/Icons/splash.jpg"));
|
|
|
|
splash->show();
|
|
|
|
// Open options file to read locale
|
2006-11-14 23:26:32 +03:00
|
|
|
QSettings settings("qBittorrent", "qBittorrent");
|
|
|
|
locale = settings.value("Options/Language/Locale", QString()).toString();
|
2006-09-30 20:02:39 +04:00
|
|
|
QTranslator translator;
|
2006-11-14 23:26:32 +03:00
|
|
|
if(locale.isEmpty()){
|
2006-09-30 20:02:39 +04:00
|
|
|
locale = QLocale::system().name();
|
2007-03-10 21:14:53 +03:00
|
|
|
settings.setValue("Options/Language/Locale", locale);
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
if(translator.load(QString(":/lang/qbittorrent_") + locale)){
|
2006-10-26 00:35:41 +04:00
|
|
|
qDebug("%s locale recognized, using translation.", (const char*)locale.toUtf8());
|
2006-09-30 20:02:39 +04:00
|
|
|
}else{
|
2006-10-26 00:35:41 +04:00
|
|
|
qDebug("%s locale unrecognized, using default (en_GB).", (const char*)locale.toUtf8());
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
app.installTranslator(&translator);
|
2007-02-27 11:37:02 +03:00
|
|
|
app.setApplicationName("qBittorrent");
|
2006-09-30 20:02:39 +04:00
|
|
|
// Read torrents given on command line
|
|
|
|
QStringList torrentCmdLine = app.arguments();
|
|
|
|
// Remove first argument (program name)
|
|
|
|
torrentCmdLine.removeFirst();
|
|
|
|
GUI window(0, torrentCmdLine);
|
|
|
|
splash->finish(&window);
|
|
|
|
delete splash;
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|