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:
commit
5e906d1767
6
qtox.pro
6
qtox.pro
|
@ -143,7 +143,8 @@ HEADERS += src/widget/form/addfriendform.h \
|
|||
src/misc/flowlayout.h \
|
||||
src/ipc.h \
|
||||
src/widget/toxuri.h \
|
||||
src/toxdns.h
|
||||
src/toxdns.h \
|
||||
src/widget/toxsave.h
|
||||
|
||||
SOURCES += \
|
||||
src/widget/form/addfriendform.cpp \
|
||||
|
@ -205,4 +206,5 @@ SOURCES += \
|
|||
src/misc/flowlayout.cpp \
|
||||
src/widget/toxuri.cpp \
|
||||
src/toxdns.cpp \
|
||||
src/ipc.cpp
|
||||
src/ipc.cpp \
|
||||
src/widget/toxsave.cpp
|
||||
|
|
17
src/ipc.cpp
17
src/ipc.cpp
|
@ -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 <QDebug>
|
||||
#include <QCoreApplication>
|
||||
|
|
17
src/ipc.h
17
src/ipc.h
|
@ -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
|
||||
#define IPC_H
|
||||
|
||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -18,16 +18,19 @@
|
|||
#include "misc/settings.h"
|
||||
#include "src/ipc.h"
|
||||
#include "src/widget/toxuri.h"
|
||||
#include "src/widget/toxsave.h"
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#ifdef LOG_TO_FILE
|
||||
static QtMessageHandler dflt;
|
||||
static QTextStream* logFile {nullptr};
|
||||
static QMutex mutex;
|
||||
|
||||
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"))
|
||||
return;
|
||||
|
||||
QMutexLocker locker(&mutex);
|
||||
dflt(type, ctxt, msg);
|
||||
*logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n';
|
||||
logFile->flush();
|
||||
|
@ -82,6 +86,7 @@ int main(int argc, char *argv[])
|
|||
// Inter-process communication
|
||||
IPC ipc;
|
||||
ipc.registerEventHandler(&toxURIEventHandler);
|
||||
ipc.registerEventHandler(&toxSaveEventHandler);
|
||||
|
||||
// Process arguments
|
||||
if (argc >= 2)
|
||||
|
@ -104,6 +109,21 @@ int main(int argc, char *argv[])
|
|||
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
|
||||
|
|
|
@ -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/misc/cdata.h"
|
||||
#include <QMessageBox>
|
||||
|
|
17
src/toxdns.h
17
src/toxdns.h
|
@ -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
|
||||
#define QTOXDNS_H
|
||||
|
||||
|
|
|
@ -201,11 +201,12 @@ void IdentityForm::onImportClicked()
|
|||
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)))
|
||||
return;
|
||||
|
||||
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
|
||||
QFile::copy(path, profilePath);
|
||||
bodyUI->profiles->addItem(profile);
|
||||
}
|
||||
|
|
78
src/widget/toxsave.cpp
Normal file
78
src/widget/toxsave.cpp
Normal 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
29
src/widget/toxsave.h
Normal 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
|
|
@ -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/toxdns.h"
|
||||
#include "src/widget/tool/friendrequestdialog.h"
|
||||
|
|
|
@ -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
|
||||
#define TOXURI_H
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user