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

add startup profile detection

This commit is contained in:
dubslow 2014-10-09 00:30:33 -05:00
parent 1bacd2da7a
commit 2181313d37
4 changed files with 71 additions and 28 deletions

View File

@ -43,8 +43,8 @@ const QString Core::TOX_EXT = ".tox";
QList<ToxFile> Core::fileSendQueue; QList<ToxFile> Core::fileSendQueue;
QList<ToxFile> Core::fileRecvQueue; QList<ToxFile> Core::fileRecvQueue;
Core::Core(Camera* cam, QThread *coreThread) : Core::Core(Camera* cam, QThread *coreThread, QString loadPath) :
tox(nullptr), camera(cam) tox(nullptr), camera(cam), loadPath(loadPath)
{ {
videobuf = new uint8_t[videobufsize]; videobuf = new uint8_t[videobufsize];
videoBusyness=0; videoBusyness=0;
@ -213,28 +213,14 @@ void Core::start()
qsrand(time(nullptr)); qsrand(time(nullptr));
// where do we find the data file? if (!loadConfiguration(loadPath)) // loadPath is meaningless after this
QString path;
{ // read data from whose profile?
path = Settings::getSettingsDirPath() + QDir::separator() + Settings::getInstance().getCurrentProfile() + TOX_EXT;
#if 1 // deprecation attempt
// if the last profile doesn't exist, fall back to old "data"
//! or maybe, should we give an option to choose other existing profiles?
QFile file(path);
if (!file.exists())
{
path = Settings::getSettingsDirPath() + QDir::separator() + CONFIG_FILE_NAME;
}
#endif
}
if (!loadConfiguration(path))
{ {
emit failedToStart(); emit failedToStart();
tox_kill(tox); tox_kill(tox);
tox = nullptr; tox = nullptr;
return; return;
} }
loadPath = "";
tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_request(tox, onFriendRequest, this);
tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_message(tox, onFriendMessage, this);
@ -1156,10 +1142,10 @@ void Core::saveConfiguration()
QString path = dir + QDir::separator() + profile + TOX_EXT; QString path = dir + QDir::separator() + profile + TOX_EXT;
QFileInfo info(path); QFileInfo info(path);
if (!info.exists()) // fall back to old school 'data' // if (!info.exists()) // fall back to old school 'data'
{ //path = dir + QDir::separator() + CONFIG_FILE_NAME; // { //path = dir + QDir::separator() + CONFIG_FILE_NAME;
qDebug() << path << " does not exist"; // qDebug() << "Core:" << path << " does not exist";
} // }
saveConfiguration(path); saveConfiguration(path);
} }

7
core.h
View File

@ -34,11 +34,12 @@ class Core : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Core(Camera* cam, QThread* coreThread); explicit Core(Camera* cam, QThread* coreThread, QString initialLoadPath);
static Core* getInstance(); ///< Returns the global widget's Core instance static Core* getInstance(); ///< Returns the global widget's Core instance
~Core(); ~Core();
static const QString TOX_EXT; static const QString TOX_EXT;
static const QString CONFIG_FILE_NAME;
int getGroupNumberPeers(int groupId) const; int getGroupNumberPeers(int groupId) const;
QString getGroupPeerName(int groupId, int peerId) const; QString getGroupPeerName(int groupId, int peerId) const;
@ -234,14 +235,14 @@ private slots:
private: private:
Tox* tox; Tox* tox;
ToxAv* toxav; ToxAv* toxav;
QTimer *toxTimer, *fileTimer, *bootstrapTimer; //, *saveTimer; QTimer *toxTimer, *fileTimer; //, *saveTimer;
Camera* camera; Camera* camera;
QString loadPath; // meaningless after start() is called
QList<DhtServer> dhtServerList; QList<DhtServer> dhtServerList;
int dhtServerId; int dhtServerId;
static QList<ToxFile> fileSendQueue, fileRecvQueue; static QList<ToxFile> fileSendQueue, fileRecvQueue;
static ToxCall calls[]; static ToxCall calls[];
static const QString CONFIG_FILE_NAME;
static const int videobufsize; static const int videobufsize;
static uint8_t* videobuf; static uint8_t* videobuf;
static int videoBusyness; // Used to know when to drop frames static int videoBusyness; // Used to know when to drop frames

View File

@ -42,6 +42,7 @@
#include <QClipboard> #include <QClipboard>
#include <QThread> #include <QThread>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog>
#include <tox/tox.h> #include <tox/tox.h>
Widget *Widget::instance{nullptr}; Widget *Widget::instance{nullptr};
@ -118,9 +119,9 @@ Widget::Widget(QWidget *parent)
qRegisterMetaType<ToxFile>("ToxFile"); qRegisterMetaType<ToxFile>("ToxFile");
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection"); qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
// QString path = detectProfiles(); QString profilePath = detectProfile();
coreThread = new QThread(this); coreThread = new QThread(this);
core = new Core(camera, coreThread/*, profile*/); core = new Core(camera, coreThread, profilePath);
core->moveToThread(coreThread); core->moveToThread(coreThread);
connect(coreThread, &QThread::started, core, &Core::start); connect(coreThread, &QThread::started, core, &Core::start);
@ -215,6 +216,59 @@ void Widget::closeEvent(QCloseEvent *event)
QWidget::closeEvent(event); QWidget::closeEvent(event);
} }
QString Widget::detectProfile()
{
QDir dir(Settings::getSettingsDirPath());
QString path, profile = Settings::getInstance().getCurrentProfile();
path = dir.filePath(profile + Core::TOX_EXT);
QFile file(path);
if (profile == "" || !file.exists())
{
#if 1 // deprecation attempt
// if the last profile doesn't exist, fall back to old "data"
path = dir.filePath(Core::CONFIG_FILE_NAME);
QFile file(path);
if (file.exists())
return path;
else
#endif
return dir.filePath(askProfiles() + Core::TOX_EXT);
}
else
return path;
}
QList<QString> Widget::searchProfiles()
{
QList<QString> out;
QDir dir(Settings::getSettingsDirPath());
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
dir.setNameFilters(QStringList("*.tox"));
for(QFileInfo file : dir.entryInfoList())
out += file.completeBaseName();
return out;
}
QString Widget::askProfiles()
{
QList<QString> profiles = searchProfiles();
bool ok;
QString profile = QInputDialog::getItem(this,
tr("Choose a profile"),
tr("Please choose which identity to use"),
profiles,
0, // which slot to start on
false, // if the user can enter their own input
&ok);
if (!ok) // user cancelled
{
qApp->quit();
return "";
}
else
return profile;
}
QString Widget::getUsername() QString Widget::getUsername()
{ {
return core->getUsername(); return core->getUsername();

View File

@ -56,6 +56,7 @@ public:
void newMessageAlert(); void newMessageAlert();
bool isFriendWidgetCurActiveWidget(Friend* f); bool isFriendWidgetCurActiveWidget(Friend* f);
bool getIsWindowMinimized(); bool getIsWindowMinimized();
static QList<QString> searchProfiles();
~Widget(); ~Widget();
virtual void closeEvent(QCloseEvent *event); virtual void closeEvent(QCloseEvent *event);
@ -112,8 +113,9 @@ private:
virtual bool event(QEvent * e); virtual bool event(QEvent * e);
Group* createGroup(int groupId); Group* createGroup(int groupId);
void removeFriend(Friend* f); void removeFriend(Friend* f);
QString askProfiles();
QString detectProfile();
private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QSplitter *centralLayout; QSplitter *centralLayout;
QPoint dragPosition; QPoint dragPosition;