diff --git a/.gitmodules b/.gitmodules index ef0a439..ceb20ba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "submodules/ProjectTox-Core"] path = submodules/ProjectTox-Core url = https://github.com/irungentoo/ProjectTox-Core.git +[submodule "submodules/ProjectTox-libtoxdata"] + path = submodules/ProjectTox-libtoxdata + url = https://github.com/jencka/ProjectTox-libtoxdata diff --git a/.travis.yml b/.travis.yml index 1e61192..0d9638c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ before_install: - sudo make install - sudo ldconfig - cd .. + - git submodule update --init --recursive script: - ~/Qt5.2.0/5.2.0/gcc_64/bin/qmake -v @@ -35,4 +36,4 @@ notifications: - "chat.freenode.net#Tox-Qt-GUI" on_success: always on_failure: always - \ No newline at end of file + diff --git a/projectfiles/QtCreator/TOX-Qt-GUI.pro b/projectfiles/QtCreator/TOX-Qt-GUI.pro index 86d7ac9..af9391a 100644 --- a/projectfiles/QtCreator/TOX-Qt-GUI.pro +++ b/projectfiles/QtCreator/TOX-Qt-GUI.pro @@ -35,7 +35,10 @@ TEMPLATE = app CONFIG += c++11 -INCLUDEPATH += ../../src/ ../../submodules/ProjectTox-Core/toxcore/ +INCLUDEPATH += \ + ../../src/ ../../submodules/ProjectTox-Core/toxcore/ \ + ../../submodules/ProjectTox-libtoxdata/ \ + ../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/ win32:INCLUDEPATH += ../../libs/sodium/include/ macx:INCLUDEPATH += /usr/local/include @@ -50,6 +53,11 @@ win32 { } win32:DEFINES += WIN32 +DEFINES += SCRYPT_SALSA SCRYPT_SHA256 + +contains(QMAKE_CC, clang) { + QMAKE_CFLAGS += -no-integrated-as +} SOURCES += \ ../../src/main.cpp \ @@ -92,7 +100,8 @@ SOURCES += \ ../../src/frienditemdelegate.cpp \ ../../src/editablelabelwidget.cpp \ ../../src/esclineedit.cpp \ - ../../src/copyableelidelabel.cpp + ../../src/copyableelidelabel.cpp \ + ../../src/profile.cpp HEADERS += \ ../../src/mainwindow.hpp \ @@ -135,7 +144,8 @@ HEADERS += \ ../../src/frienditemdelegate.hpp \ ../../src/editablelabelwidget.hpp \ ../../src/esclineedit.hpp \ - ../../src/copyableelidelabel.hpp + ../../src/copyableelidelabel.hpp \ + ../../src/profile.hpp SOURCES += \ ../../submodules/ProjectTox-Core/toxcore/DHT.c \ @@ -166,6 +176,14 @@ HEADERS += \ ../../submodules/ProjectTox-Core/toxcore/group_chats.h \ ../../submodules/ProjectTox-Core/toxcore/assoc.h +SOURCES += \ + ../../submodules/ProjectTox-libtoxdata/tox_data.c \ + ../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/scrypt-jane.c + +HEADERS += \ + ../../submodules/ProjectTox-libtoxdata/tox_data.h \ + ../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/scrypt-jane.h + RESOURCES += \ ../../resources/resources.qrc diff --git a/src/profile.cpp b/src/profile.cpp new file mode 100644 index 0000000..7b4ee7b --- /dev/null +++ b/src/profile.cpp @@ -0,0 +1,89 @@ +#include "profile.hpp" + +Profile::Profile(QString filePath) +{ + pData = data_init_load((char*)filePath.toLocal8Bit().constData()); + if (pData == NULL) + brokenProfile(); +} + +Profile::Profile(QString filePath, QString name, QString password) +{ + pData = data_init_new((char*)filePath.toLocal8Bit().constData(), (uint8_t*)name.toUtf8().constData(), (uint8_t*)password.toUtf8().constData()); + if (pData == NULL) + brokenProfile(); +} + +Profile::~Profile() +{ + if(!pData->locked) + data_lock(pData); + data_close(pData); +} + +int Profile::unlock(QString password) +{ + return data_unlock(pData, (uint8_t*)password.toUtf8().constData()); +} + +void Profile::changeName(QString newName) +{ + free(pData->name); + pData->name = (uint8_t*)malloc(newName.toUtf8().size()); + memcpy(pData->name, newName.toUtf8().constData(), newName.toUtf8().size()); +} + +QString Profile::getName() +{ + return QString::fromLocal8Bit((const char*)pData->name); +} + +QDateTime Profile::getSaveTime() +{ + return QDateTime::fromMSecsSinceEpoch(pData->time_saved); +} + +bool Profile::isLocked() +{ + return pData->locked; +} + +int Profile::lock() +{ + return data_lock(pData); +} + +int Profile::changePassword(QString oldPassword, QString newPassword) +{ + return data_change_key(pData, (uint8_t*)oldPassword.toUtf8().constData(), (uint8_t*)newPassword.toUtf8().constData()); +} + +int Profile::loadMessenger(Tox *tox) +{ + size_t size = data_messenger_size(pData); + uint8_t buffer[size]; + data_read_messenger(pData, buffer); + if(tox_load(tox, buffer, size) != 0) + return -1; + return 0; +} + +int Profile::saveMessenger(Tox *tox) +{ + size_t size = tox_size(tox); + uint8_t buffer[size]; + tox_save(tox, buffer); + return data_write_messenger(pData, buffer, size); +} + +int Profile::flush() +{ + return data_flush(pData); +} + +void Profile::brokenProfile() +{ + //Create a profile that won't be unlocked. This will probably never be called. + QString path = QDir::tempPath() + "/" + QCoreApplication::applicationName() + "." + QString::number(qrand()); + pData = data_init_new((char*)path.toLocal8Bit().constData(), (uint8_t*)"Broken Profile!", (uint8_t*)"don'tlogin"); +} diff --git a/src/profile.hpp b/src/profile.hpp new file mode 100644 index 0000000..f59967f --- /dev/null +++ b/src/profile.hpp @@ -0,0 +1,67 @@ +#ifndef PROFILE_H +#define PROFILE_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +class Profile : public QObject +{ + Q_OBJECT +public: + /* See tox_data.h for full documentation on function return values & behavior. */ + + /* Loads a profile from the given path. + * Throws an exception (0) if the profile can't be loaded. + */ + Profile(QString filePath); + /* Creates a new profile. + * This profile isn't saved to disk until lock() or save() are called. + */ + Profile(QString filePath, QString name, QString password); + ~Profile(); + + int unlock(QString password); + + /* Changes the saved name for the profile. */ + void changeName(QString newName); + /* Returns the profile's name. */ + QString getName(); + /* Returns the last date that the profile was saved. */ + QDateTime getSaveTime(); + + /* Checks if the profile is locked. */ + bool isLocked(); + + /* ------------- REQUIRES UNLOCKING ------------- */ + + int lock(); + int changePassword(QString oldPassword, QString newPassword); + + /* Loads the given messenger + * + * returns 0 if success + */ + int loadMessenger(Tox *tox); + + /* Saves the given messenger + * + * returns 0 if success + */ + int saveMessenger(Tox *tox); + + int flush(); + +private: + void brokenProfile(); + tox_data *pData; +}; + +#endif // PROFILE_H diff --git a/submodules/ProjectTox-libtoxdata b/submodules/ProjectTox-libtoxdata new file mode 160000 index 0000000..6bd2572 --- /dev/null +++ b/submodules/ProjectTox-libtoxdata @@ -0,0 +1 @@ +Subproject commit 6bd25721180b475eba33c75d2d0d668df679303c