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 "core.h"
|
||||
#include "misc/settings.h"
|
||||
#include "misc/style.h"
|
||||
#include <math.h>
|
||||
#include <QFileDialog>
|
||||
|
@ -81,24 +82,28 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
|
|||
|
||||
// state = tsProcessing;
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
if (lastUpdateTime.secsTo(now) < 1) //update every 1s
|
||||
long recenttimediff = lastUpdateTime.msecsTo(now);
|
||||
if (recenttimediff < 1000) //update every 1s
|
||||
return;
|
||||
|
||||
int timediff = effStartTime.secsTo(now);
|
||||
long timediff = effStartTime.msecsTo(now);
|
||||
if (timediff <= 0)
|
||||
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);
|
||||
totalBytes = Filesize;
|
||||
if (!rawspeed)
|
||||
|
||||
if (!avgspeed)
|
||||
return;
|
||||
int etaSecs = (Filesize - BytesSent) / rawspeed;
|
||||
int etaSecs = (Filesize - BytesSent) / avgspeed;
|
||||
QTime etaTime(0,0);
|
||||
etaTime = etaTime.addSecs(etaSecs);
|
||||
eta = etaTime.toString("mm:ss");
|
||||
|
||||
lastBytesSent = BytesSent;
|
||||
lastUpdateTime = now;
|
||||
emit stateUpdated();
|
||||
|
@ -203,21 +208,38 @@ bool isFileWritable(QString& path)
|
|||
|
||||
void FileTransferInstance::acceptRecvRequest()
|
||||
{
|
||||
QString path;
|
||||
while (true)
|
||||
QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId));
|
||||
if (!path.isEmpty())
|
||||
{
|
||||
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
else
|
||||
QDir dir(path);
|
||||
path = dir.filePath(filename);
|
||||
QFileInfo info(path);
|
||||
if (info.exists()) // emulate chrome
|
||||
{
|
||||
//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))
|
||||
break;
|
||||
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)
|
||||
{
|
||||
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
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"));
|
||||
{
|
||||
if (isFileWritable(path))
|
||||
break;
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "settings.h"
|
||||
#include "smileypack.h"
|
||||
#include "src/corestructs.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QApplication>
|
||||
|
@ -151,6 +152,11 @@ void Settings::load()
|
|||
typingNotification = s.value("typingNotification", false).toBool();
|
||||
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
|
||||
if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty())
|
||||
smileyPack = SmileyPack::listSmileyPacks()[0].second;
|
||||
|
@ -258,6 +264,11 @@ void Settings::save(QString path)
|
|||
s.beginGroup("Privacy");
|
||||
s.setValue("typingNotification", typingNotification);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("AutoAccept");
|
||||
for (auto& id : autoAccept.keys())
|
||||
s.setValue(id, autoAccept.value(id));
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
QString Settings::getSettingsDirPath()
|
||||
|
@ -480,6 +491,19 @@ void Settings::setAutoAwayTime(int 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)
|
||||
{
|
||||
widgetSettings[uniqueName] = data;
|
||||
|
|
|
@ -125,6 +125,9 @@ public:
|
|||
int getEmojiFontPointSize() const;
|
||||
void setEmojiFontPointSize(int value);
|
||||
|
||||
QString getAutoAcceptDir(const QString& id) const;
|
||||
void setAutoAcceptDir(const QString&id, const QString& dir);
|
||||
|
||||
// ChatView
|
||||
int getFirstColumnHandlePos() const;
|
||||
void setFirstColumnHandlePos(const int pos);
|
||||
|
@ -197,6 +200,7 @@ private:
|
|||
int autoAwayTime;
|
||||
|
||||
QHash<QString, QByteArray> widgetSettings;
|
||||
QHash<QString, QString> autoAccept;
|
||||
|
||||
// GUI
|
||||
bool enableSmoothAnimation;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "src/widget/maskablepixmapwidget.h"
|
||||
#include "src/widget/croppinglabel.h"
|
||||
#include "src/misc/style.h"
|
||||
#include "src/misc/settings.h"
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
: f(chatFriend)
|
||||
|
@ -178,6 +179,9 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
previousName = f->getName();
|
||||
|
||||
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)
|
||||
|
|
|
@ -25,12 +25,15 @@
|
|||
#include "maskablepixmapwidget.h"
|
||||
#include "croppinglabel.h"
|
||||
#include "src/misc/style.h"
|
||||
#include "src/misc/settings.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QApplication>
|
||||
#include <QBitmap>
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
|
||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||
: friendId(FriendId)
|
||||
|
@ -44,6 +47,8 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
|||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
{
|
||||
QPoint pos = event->globalPos();
|
||||
QString id = Core::getInstance()->getFriendAddress(friendId);
|
||||
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
||||
QMenu menu;
|
||||
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"));
|
||||
|
@ -55,6 +60,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
}
|
||||
if (groupActions.isEmpty())
|
||||
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();
|
||||
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);
|
||||
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))
|
||||
{
|
||||
Group* group = groupActions[selectedItem];
|
||||
|
|
Loading…
Reference in New Issue
Block a user