1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr664'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-07 23:19:27 +01:00
commit 5e906d1767
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
11 changed files with 236 additions and 4 deletions

View File

@ -143,7 +143,8 @@ HEADERS += src/widget/form/addfriendform.h \
src/misc/flowlayout.h \ src/misc/flowlayout.h \
src/ipc.h \ src/ipc.h \
src/widget/toxuri.h \ src/widget/toxuri.h \
src/toxdns.h src/toxdns.h \
src/widget/toxsave.h
SOURCES += \ SOURCES += \
src/widget/form/addfriendform.cpp \ src/widget/form/addfriendform.cpp \
@ -205,4 +206,5 @@ SOURCES += \
src/misc/flowlayout.cpp \ src/misc/flowlayout.cpp \
src/widget/toxuri.cpp \ src/widget/toxuri.cpp \
src/toxdns.cpp \ src/toxdns.cpp \
src/ipc.cpp src/ipc.cpp \
src/widget/toxsave.cpp

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#include "src/ipc.h" #include "src/ipc.h"
#include <QDebug> #include <QDebug>
#include <QCoreApplication> #include <QCoreApplication>

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#ifndef IPC_H #ifndef IPC_H
#define IPC_H #define IPC_H

View File

@ -18,16 +18,19 @@
#include "misc/settings.h" #include "misc/settings.h"
#include "src/ipc.h" #include "src/ipc.h"
#include "src/widget/toxuri.h" #include "src/widget/toxuri.h"
#include "src/widget/toxsave.h"
#include <QApplication> #include <QApplication>
#include <QFontDatabase> #include <QFontDatabase>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QDateTime> #include <QDateTime>
#include <QMutexLocker>
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
static QtMessageHandler dflt; static QtMessageHandler dflt;
static QTextStream* logFile {nullptr}; static QTextStream* logFile {nullptr};
static QMutex mutex;
void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg) void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg)
{ {
@ -39,6 +42,7 @@ void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QStr
&& msg == QString("QFSFileEngine::open: No file name specified")) && msg == QString("QFSFileEngine::open: No file name specified"))
return; return;
QMutexLocker locker(&mutex);
dflt(type, ctxt, msg); dflt(type, ctxt, msg);
*logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n'; *logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n';
logFile->flush(); logFile->flush();
@ -82,6 +86,7 @@ int main(int argc, char *argv[])
// Inter-process communication // Inter-process communication
IPC ipc; IPC ipc;
ipc.registerEventHandler(&toxURIEventHandler); ipc.registerEventHandler(&toxURIEventHandler);
ipc.registerEventHandler(&toxSaveEventHandler);
// Process arguments // Process arguments
if (argc >= 2) if (argc >= 2)
@ -104,6 +109,21 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }
else if (firstParam.endsWith(".tox"))
{
if (ipc.isCurrentOwner()) // Don't bother sending an event if we're going to process it ourselves
{
handleToxSave(firstParam.toUtf8());
}
else
{
time_t event = ipc.postEvent(firstParam.toUtf8());
ipc.waitUntilProcessed(event);
// If someone else processed it, we're done here, no need to actually start qTox
if (!ipc.isCurrentOwner())
return EXIT_SUCCESS;
}
}
} }
// Run // Run

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#include "src/toxdns.h" #include "src/toxdns.h"
#include "src/misc/cdata.h" #include "src/misc/cdata.h"
#include <QMessageBox> #include <QMessageBox>

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#ifndef QTOXDNS_H #ifndef QTOXDNS_H
#define QTOXDNS_H #define QTOXDNS_H

View File

@ -201,11 +201,12 @@ void IdentityForm::onImportClicked()
return; return;
} }
if (info.exists() && !checkContinue(tr("Profile already exists", "import confirm title"), QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
if (QFileInfo(profilePath).exists() && !checkContinue(tr("Profile already exists", "import confirm title"),
tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile))) tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
return; return;
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
QFile::copy(path, profilePath); QFile::copy(path, profilePath);
bodyUI->profiles->addItem(profile); bodyUI->profiles->addItem(profile);
} }

78
src/widget/toxsave.cpp Normal file
View File

@ -0,0 +1,78 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#include "toxsave.h"
#include "widget.h"
#include "src/core.h"
#include "src/misc/settings.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
void toxSaveEventHandler(const QByteArray& eventData)
{
if (!eventData.endsWith(".tox"))
return;
handleToxSave(eventData);
}
static bool checkContinue(const QString& title, const QString& msg)
{
QMessageBox::StandardButton resp = QMessageBox::question(Widget::getInstance(), title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
return resp == QMessageBox::Yes;
}
void handleToxSave(const QString& path)
{
Core* core = Core::getInstance();
while (!core)
{
core = Core::getInstance();
qApp->processEvents();
}
while (!core->isReady())
{
qApp->processEvents();
}
QFileInfo info(path);
if (!info.exists())
return;
QString profile = info.completeBaseName();
if (info.suffix() != "tox")
{
QMessageBox::warning(Widget::getInstance(),
QObject::tr("Ignoring non-Tox file", "popup title"),
QObject::tr("Warning: you've chosen a file that is not a Tox save file; ignoring.", "popup text"));
return;
}
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
if (QFileInfo(profilePath).exists() && !checkContinue(QObject::tr("Profile already exists", "import confirm title"),
QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
return;
QFile::copy(path, profilePath);
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
// such a thing would simplify other code as well I believe
QMessageBox::information(Widget::getInstance(), QObject::tr("Profile imported"), QObject::tr("%1.tox was successfully imported").arg(profile));
}

29
src/widget/toxsave.h Normal file
View File

@ -0,0 +1,29 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#ifndef TOXSAVE_H
#define TOXSAVE_H
class QString;
class QByteArray;
/// Will wait until the core is ready first
void handleToxSave(const QString& path);
// Internals
void toxSaveEventHandler(const QByteArray& eventData);
#endif

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#include "src/widget/toxuri.h" #include "src/widget/toxuri.h"
#include "src/toxdns.h" #include "src/toxdns.h"
#include "src/widget/tool/friendrequestdialog.h" #include "src/widget/tool/friendrequestdialog.h"

View File

@ -1,3 +1,20 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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.
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 COPYING file for more details.
*/
#ifndef TOXURI_H #ifndef TOXURI_H
#define TOXURI_H #define TOXURI_H