mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr463'
This commit is contained in:
commit
c21b5fe6bb
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "filetransferinstance.h"
|
#include "filetransferinstance.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "misc/settings.h"
|
||||||
#include "misc/style.h"
|
#include "misc/style.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
@ -81,24 +82,28 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
|
||||||
|
|
||||||
// state = tsProcessing;
|
// state = tsProcessing;
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
if (lastUpdateTime.secsTo(now) < 1) //update every 1s
|
long recenttimediff = lastUpdateTime.msecsTo(now);
|
||||||
|
if (recenttimediff < 1000) //update every 1s
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int timediff = effStartTime.secsTo(now);
|
long timediff = effStartTime.msecsTo(now);
|
||||||
if (timediff <= 0)
|
if (timediff <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
long rawspeed = (BytesSent - previousBytesSent) / timediff;
|
long avgspeed = (BytesSent - previousBytesSent) / timediff * 1000;
|
||||||
|
long recentspeed = (BytesSent - lastBytesSent) / recenttimediff * 1000;
|
||||||
|
|
||||||
speed = getHumanReadableSize(rawspeed)+"/s";
|
speed = getHumanReadableSize(recentspeed)+"/s";
|
||||||
size = getHumanReadableSize(Filesize);
|
size = getHumanReadableSize(Filesize);
|
||||||
totalBytes = Filesize;
|
totalBytes = Filesize;
|
||||||
if (!rawspeed)
|
|
||||||
|
if (!avgspeed)
|
||||||
return;
|
return;
|
||||||
int etaSecs = (Filesize - BytesSent) / rawspeed;
|
int etaSecs = (Filesize - BytesSent) / avgspeed;
|
||||||
QTime etaTime(0,0);
|
QTime etaTime(0,0);
|
||||||
etaTime = etaTime.addSecs(etaSecs);
|
etaTime = etaTime.addSecs(etaSecs);
|
||||||
eta = etaTime.toString("mm:ss");
|
eta = etaTime.toString("mm:ss");
|
||||||
|
|
||||||
lastBytesSent = BytesSent;
|
lastBytesSent = BytesSent;
|
||||||
lastUpdateTime = now;
|
lastUpdateTime = now;
|
||||||
emit stateUpdated();
|
emit stateUpdated();
|
||||||
|
@ -203,7 +208,26 @@ bool isFileWritable(QString& path)
|
||||||
|
|
||||||
void FileTransferInstance::acceptRecvRequest()
|
void FileTransferInstance::acceptRecvRequest()
|
||||||
{
|
{
|
||||||
QString path;
|
QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId));
|
||||||
|
if (!path.isEmpty())
|
||||||
|
{
|
||||||
|
QDir dir(path);
|
||||||
|
path = dir.filePath(filename);
|
||||||
|
QFileInfo info(path);
|
||||||
|
if (info.exists()) // emulate chrome
|
||||||
|
{
|
||||||
|
QString name = info.baseName(), ext = info.completeSuffix();
|
||||||
|
int i = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
path = dir.filePath(name + QString(" (%1)").arg(++i) + "." + ext);
|
||||||
|
}
|
||||||
|
while (QFileInfo(path).exists());
|
||||||
|
}
|
||||||
|
qDebug() << "File: auto saving to" << path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
|
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
|
||||||
|
@ -211,15 +235,13 @@ void FileTransferInstance::acceptRecvRequest()
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//bool savable = QFileInfo(path).isWritable();
|
|
||||||
//qDebug() << path << " is writable: " << savable;
|
|
||||||
//qDebug() << "/home/bill/bliss.pdf writable: " << QFileInfo("/home/bill/bliss.pdf").isWritable();
|
|
||||||
if (isFileWritable(path))
|
if (isFileWritable(path))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
QMessageBox::warning(0, tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
|
QMessageBox::warning(0, tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
savePath = path;
|
savePath = path;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "smileypack.h"
|
#include "smileypack.h"
|
||||||
|
#include "src/corestructs.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -151,6 +152,11 @@ void Settings::load()
|
||||||
typingNotification = s.value("typingNotification", false).toBool();
|
typingNotification = s.value("typingNotification", false).toBool();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
s.beginGroup("AutoAccept");
|
||||||
|
for (auto& key : s.childKeys())
|
||||||
|
autoAccept[key] = s.value(key).toString();
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
// try to set a smiley pack if none is selected
|
// try to set a smiley pack if none is selected
|
||||||
if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty())
|
if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty())
|
||||||
smileyPack = SmileyPack::listSmileyPacks()[0].second;
|
smileyPack = SmileyPack::listSmileyPacks()[0].second;
|
||||||
|
@ -258,6 +264,11 @@ void Settings::save(QString path)
|
||||||
s.beginGroup("Privacy");
|
s.beginGroup("Privacy");
|
||||||
s.setValue("typingNotification", typingNotification);
|
s.setValue("typingNotification", typingNotification);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
s.beginGroup("AutoAccept");
|
||||||
|
for (auto& id : autoAccept.keys())
|
||||||
|
s.setValue(id, autoAccept.value(id));
|
||||||
|
s.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Settings::getSettingsDirPath()
|
QString Settings::getSettingsDirPath()
|
||||||
|
@ -480,6 +491,19 @@ void Settings::setAutoAwayTime(int newValue)
|
||||||
autoAwayTime = newValue;
|
autoAwayTime = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::getAutoAcceptDir(const QString& id) const
|
||||||
|
{
|
||||||
|
return autoAccept.value(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setAutoAcceptDir(const QString& id, const QString& dir)
|
||||||
|
{
|
||||||
|
if (dir.isEmpty())
|
||||||
|
autoAccept.remove(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
|
||||||
|
else
|
||||||
|
autoAccept[id.left(TOX_ID_PUBLIC_KEY_LENGTH)] = dir;
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
|
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
|
||||||
{
|
{
|
||||||
widgetSettings[uniqueName] = data;
|
widgetSettings[uniqueName] = data;
|
||||||
|
|
|
@ -125,6 +125,9 @@ public:
|
||||||
int getEmojiFontPointSize() const;
|
int getEmojiFontPointSize() const;
|
||||||
void setEmojiFontPointSize(int value);
|
void setEmojiFontPointSize(int value);
|
||||||
|
|
||||||
|
QString getAutoAcceptDir(const QString& id) const;
|
||||||
|
void setAutoAcceptDir(const QString&id, const QString& dir);
|
||||||
|
|
||||||
// ChatView
|
// ChatView
|
||||||
int getFirstColumnHandlePos() const;
|
int getFirstColumnHandlePos() const;
|
||||||
void setFirstColumnHandlePos(const int pos);
|
void setFirstColumnHandlePos(const int pos);
|
||||||
|
@ -197,6 +200,7 @@ private:
|
||||||
int autoAwayTime;
|
int autoAwayTime;
|
||||||
|
|
||||||
QHash<QString, QByteArray> widgetSettings;
|
QHash<QString, QByteArray> widgetSettings;
|
||||||
|
QHash<QString, QString> autoAccept;
|
||||||
|
|
||||||
// GUI
|
// GUI
|
||||||
bool enableSmoothAnimation;
|
bool enableSmoothAnimation;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "src/widget/maskablepixmapwidget.h"
|
#include "src/widget/maskablepixmapwidget.h"
|
||||||
#include "src/widget/croppinglabel.h"
|
#include "src/widget/croppinglabel.h"
|
||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
|
#include "src/misc/settings.h"
|
||||||
|
|
||||||
ChatForm::ChatForm(Friend* chatFriend)
|
ChatForm::ChatForm(Friend* chatFriend)
|
||||||
: f(chatFriend)
|
: f(chatFriend)
|
||||||
|
@ -178,6 +179,9 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
previousName = f->getName();
|
previousName = f->getName();
|
||||||
|
|
||||||
chatWidget->insertMessage(new FileTransferAction(fileTrans, getElidedName(name), QTime::currentTime().toString("hh:mm"), false));
|
chatWidget->insertMessage(new FileTransferAction(fileTrans, getElidedName(name), QTime::currentTime().toString("hh:mm"), false));
|
||||||
|
|
||||||
|
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty())
|
||||||
|
fileTrans->pressFromHtml("btnB");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
||||||
|
|
|
@ -25,12 +25,15 @@
|
||||||
#include "maskablepixmapwidget.h"
|
#include "maskablepixmapwidget.h"
|
||||||
#include "croppinglabel.h"
|
#include "croppinglabel.h"
|
||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
|
#include "src/misc/settings.h"
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
: friendId(FriendId)
|
: friendId(FriendId)
|
||||||
|
@ -44,6 +47,8 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
{
|
{
|
||||||
QPoint pos = event->globalPos();
|
QPoint pos = event->globalPos();
|
||||||
|
QString id = Core::getInstance()->getFriendAddress(friendId);
|
||||||
|
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
|
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"));
|
QMenu* inviteMenu = menu.addMenu(tr("Invite in group","Menu to invite a friend in a groupchat"));
|
||||||
|
@ -55,6 +60,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
}
|
}
|
||||||
if (groupActions.isEmpty())
|
if (groupActions.isEmpty())
|
||||||
inviteMenu->setEnabled(false);
|
inviteMenu->setEnabled(false);
|
||||||
|
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"));
|
||||||
|
if (dir.isEmpty())
|
||||||
|
disableAutoAccept->setEnabled(false);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||||
|
|
||||||
|
@ -74,6 +83,21 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
emit removeFriend(friendId);
|
emit removeFriend(friendId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (selectedItem == autoAccept)
|
||||||
|
{
|
||||||
|
if (dir.isEmpty())
|
||||||
|
dir = QDir::homePath();
|
||||||
|
dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
|
||||||
|
if (!dir.isEmpty())
|
||||||
|
{
|
||||||
|
qDebug() << "FriendWidget: setting auto accept dir for" << friendId << "to" << dir;
|
||||||
|
Settings::getInstance().setAutoAcceptDir(id, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (selectedItem == disableAutoAccept)
|
||||||
|
{
|
||||||
|
Settings::getInstance().setAutoAcceptDir(id, "");
|
||||||
|
}
|
||||||
else if (groupActions.contains(selectedItem))
|
else if (groupActions.contains(selectedItem))
|
||||||
{
|
{
|
||||||
Group* group = groupActions[selectedItem];
|
Group* group = groupActions[selectedItem];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user