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

Merge branch 'pr487'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-20 12:57:24 +02:00
commit 55225aca0f
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
12 changed files with 110 additions and 27 deletions

View File

@ -226,6 +226,12 @@ void Core::start()
}
loadPath = "";
}
else // new ID
{
setStatusMessage(tr("Toxing on qTox")); // this also solves the not updating issue
setUsername(tr("qTox User"));
Widget::getInstance()->onSettingsClicked(); // update ui with new profile (im worried about threading, but it seems to work)
}
tox_callback_friend_request(tox, onFriendRequest, this);
tox_callback_friend_message(tox, onFriendMessage, this);
@ -1187,10 +1193,7 @@ void Core::saveConfiguration(const QString& path)
void Core::switchConfiguration(const QString& profile)
{
if (profile.isEmpty())
{
qWarning() << "Core: got null profile to switch to, not switching";
return;
}
qDebug() << "Core: creating new Id";
else
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
saveConfiguration();
@ -1205,8 +1208,11 @@ void Core::switchConfiguration(const QString& profile)
}
emit selfAvatarChanged(QPixmap(":/img/contact_dark.png"));
emit blockingClearContacts(); // we need this to block, but signals are required for thread safety
loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT);
if (profile.isEmpty())
loadPath = "";
else
loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT);
Settings::getInstance().setCurrentProfile(profile);
start();

View File

@ -46,7 +46,7 @@ FileTransferInstance::FileTransferInstance(ToxFile File)
filenameElided = fm.elidedText(filename, Qt::ElideRight, MAX_CONTENT_WIDTH);
size = getHumanReadableSize(File.filesize);
contentPrefWidth = std::max(fm.width(filenameElided), fm.width(size));
contentPrefWidth = std::max(fm.boundingRect(filenameElided).width(), fm.width(size));
speed = "0B/s";
eta = "00:00";
@ -209,6 +209,7 @@ bool isFileWritable(QString& path)
void FileTransferInstance::acceptRecvRequest()
{
QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId));
if (path.isEmpty()) path = Settings::getInstance().getGlobalAutoAcceptDir();
if (!path.isEmpty())
{
QDir dir(path);

View File

@ -153,6 +153,7 @@ void Settings::load()
s.endGroup();
s.beginGroup("AutoAccept");
globalAutoAcceptDir = s.value("globalAutoAcceptDir", "").toString();
for (auto& key : s.childKeys())
autoAccept[key] = s.value(key).toString();
s.endGroup();
@ -266,6 +267,7 @@ void Settings::save(QString path)
s.endGroup();
s.beginGroup("AutoAccept");
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
for (auto& id : autoAccept.keys())
s.setValue(id, autoAccept.value(id));
s.endGroup();
@ -504,6 +506,16 @@ void Settings::setAutoAcceptDir(const QString& id, const QString& dir)
autoAccept[id.left(TOX_ID_PUBLIC_KEY_LENGTH)] = dir;
}
QString Settings::getGlobalAutoAcceptDir() const
{
return globalAutoAcceptDir;
}
void Settings::setGlobalAutoAcceptDir(const QString& newValue)
{
globalAutoAcceptDir = newValue;
}
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
widgetSettings[uniqueName] = data;

View File

@ -128,6 +128,9 @@ public:
QString getAutoAcceptDir(const QString& id) const;
void setAutoAcceptDir(const QString&id, const QString& dir);
QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir);
// ChatView
int getFirstColumnHandlePos() const;
void setFirstColumnHandlePos(const int pos);
@ -201,6 +204,7 @@ private:
QHash<QString, QByteArray> widgetSettings;
QHash<QString, QString> autoAccept;
QString globalAutoAcceptDir;
// GUI
bool enableSmoothAnimation;

View File

@ -154,4 +154,6 @@ void AddFriendForm::handleDnsLookup()
// finally we got it
emit friendRequested(friendAdress, getMessage());
this->toxId.setText("");
this->message.setText("");
}

View File

@ -180,7 +180,8 @@ void ChatForm::onFileRecvRequest(ToxFile file)
chatWidget->insertMessage(new FileTransferAction(fileTrans, getElidedName(name), QTime::currentTime().toString("hh:mm"), false));
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty())
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty()
|| !Settings::getInstance().getGlobalAutoAcceptDir().isEmpty())
fileTrans->pressFromHtml("btnB");
}

View File

@ -54,6 +54,7 @@ IdentityForm::IdentityForm() :
connect(bodyUI->exportButton, &QPushButton::clicked, this, &IdentityForm::onExportClicked);
connect(bodyUI->deleteButton, &QPushButton::clicked, this, &IdentityForm::onDeleteClicked);
connect(bodyUI->importButton, &QPushButton::clicked, this, &IdentityForm::onImportClicked);
connect(bodyUI->newButton, &QPushButton::clicked, this, &IdentityForm::onNewClicked);
connect(Core::getInstance(), &Core::usernameSet, this, [=](const QString& val) { bodyUI->userName->setText(val); });
connect(Core::getInstance(), &Core::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); });
@ -120,15 +121,22 @@ void IdentityForm::onRenameClicked()
{
QString cur = bodyUI->profiles->currentText();
QString title = tr("Rename \"%1\"", "renaming a profile").arg(cur);
QString name = QInputDialog::getText(this, title, title+":");
if (name != "")
do
{
QString name = QInputDialog::getText(this, title, title+":");
if (name.isEmpty()) break;
name = Core::sanitize(name);
QDir dir(Settings::getSettingsDirPath());
QFile::rename(dir.filePath(cur+Core::TOX_EXT), dir.filePath(name+Core::TOX_EXT));
bodyUI->profiles->setItemText(bodyUI->profiles->currentIndex(), name);
Settings::getInstance().setCurrentProfile(name);
}
QString file = dir.filePath(name+Core::TOX_EXT);
if (!QFile::exists(file) || checkContinue(tr("Profile already exists", "rename confirm title"),
tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur)))
{
QFile::rename(dir.filePath(cur+Core::TOX_EXT), file);
bodyUI->profiles->setItemText(bodyUI->profiles->currentIndex(), name);
Settings::getInstance().setCurrentProfile(name);
break;
}
} while (true);
}
void IdentityForm::onExportClicked()
@ -149,9 +157,8 @@ void IdentityForm::onDeleteClicked()
}
else
{
QMessageBox::StandardButton resp = QMessageBox::question(this,
tr("Deletion imminent!","deletion confirmation title"), tr("Are you sure you want to delete this profile?","deletion confirmation text"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (resp == QMessageBox::Yes)
if (checkContinue(tr("Deletion imminent!","deletion confirmation title"),
tr("Are you sure you want to delete this profile?","deletion confirmation text")))
{
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath(bodyUI->profiles->currentText()+Core::TOX_EXT));
bodyUI->profiles->removeItem(bodyUI->profiles->currentIndex());
@ -167,6 +174,7 @@ void IdentityForm::onImportClicked()
return;
QFileInfo info(path);
QString profile = info.completeBaseName();
if (info.suffix() != "tox")
{
@ -174,8 +182,22 @@ void IdentityForm::onImportClicked()
return;
}
QString profile = info.completeBaseName();
if (info.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);
}
void IdentityForm::onNewClicked()
{
emit Widget::getInstance()->changeProfile(QString());
}
bool IdentityForm::checkContinue(const QString& title, const QString& msg)
{
QMessageBox::StandardButton resp = QMessageBox::question(this, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
return resp == QMessageBox::Yes;
}

View File

@ -63,6 +63,8 @@ private slots:
void onExportClicked();
void onDeleteClicked();
void onImportClicked();
void onNewClicked();
bool checkContinue(const QString& title, const QString& msg);
private:
Ui::IdentitySettings* bodyUI;

View File

@ -122,11 +122,22 @@
</layout>
</item>
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string comment="import profile button">Import a profile</string>
</property>
</widget>
<layout class="QHBoxLayout" name="profilesButtonsLayout2">
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string comment="import profile button">Import a profile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newButton">
<property name="text">
<string comment="new profile button">New Tox ID</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

View File

@ -49,9 +49,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
QPoint pos = event->globalPos();
QString id = Core::getInstance()->getFriendAddress(friendId);
QString dir = Settings::getInstance().getAutoAcceptDir(id);
QString globalDir = Settings::getInstance().getGlobalAutoAcceptDir();
QMenu menu;
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
QMenu* inviteMenu = menu.addMenu(tr("Invite in group","Menu to invite a friend in a groupchat"));
QMap<QAction*, Group*> groupActions;
for (Group* group : GroupList::groupList)
{
@ -60,10 +61,15 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
}
if (groupActions.isEmpty())
inviteMenu->setEnabled(false);
menu.addSeparator();
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
QAction* disableAutoAccept = menu.addAction(tr("Diasble auto accepting files", "context menu entry"));
QAction* disableAutoAccept = menu.addAction(tr("Manually accept files from this friend", "context menu entry"));
QAction* globalAA = menu.addAction(tr("Auto accept files from all friends", "context menu entry"));
QAction* disableGlobalAA = menu.addAction(tr("Disable global auto accept", "context menu entry"));
if (dir.isEmpty())
disableAutoAccept->setEnabled(false);
if (globalDir.isEmpty())
disableGlobalAA->setEnabled(false);
menu.addSeparator();
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
@ -98,6 +104,21 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{
Settings::getInstance().setAutoAcceptDir(id, "");
}
else if (selectedItem == globalAA)
{
if (globalDir.isEmpty())
globalDir = QDir::homePath();
globalDir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
if (!globalDir.isEmpty())
{
qDebug() << "FriendWidget: setting global auto accept dir to" << globalDir;
Settings::getInstance().setGlobalAutoAcceptDir(globalDir);
}
}
else if (selectedItem == disableGlobalAA)
{
Settings::getInstance().setGlobalAutoAcceptDir("");
}
else if (groupActions.contains(selectedItem))
{
Group* group = groupActions[selectedItem];

View File

@ -148,7 +148,6 @@ void Widget::init()
filesForm = new FilesForm();
addFriendForm = new AddFriendForm;
settingsWidget = new SettingsWidget();
connect(core, &Core::connected, this, &Widget::onConnected);
connect(core, &Core::disconnected, this, &Widget::onDisconnected);

View File

@ -66,6 +66,9 @@ public:
virtual void closeEvent(QCloseEvent *event);
public slots:
void onSettingsClicked();
signals:
void friendRequestAccepted(const QString& userId);
void friendRequested(const QString& friendAddress, const QString& message);
@ -82,7 +85,6 @@ private slots:
void onAddClicked();
void onGroupClicked();
void onTransferClicked();
void onSettingsClicked();
void onFailedToStartCore();
void onBadProxyCore();
void onAvatarClicked();