@ -0,0 +1,166 @@ |
|||||||
|
##Dependencies |
||||||
|
|
||||||
|
| Name | Version | Modules | |
||||||
|
|--------------|-------------|-------------------------------- | |
||||||
|
| Qt | >= 5.2.0 | core, gui, network, widget, xml | |
||||||
|
| GCC/MinGW | >= 4.6 | C++11 enabled | |
||||||
|
| Tox Core | most recent | core, av | |
||||||
|
| OpenCV | >= 2.4.9 | core, highgui | |
||||||
|
| OpenAL Soft | >= 1.16.0 | | |
||||||
|
|
||||||
|
##Windows |
||||||
|
|
||||||
|
###Qt |
||||||
|
|
||||||
|
Download the Qt online installer for Windows from [qt-project.org](http://qt-project.org/downloads). |
||||||
|
While installation you have to assemble your Qt toolchain. Take the most recent version of Qt compiled with MinGW. |
||||||
|
Although the installer provides its own bundled MinGW compiler toolchain its recommend installing it separately because Qt is missing MSYS which is needed to compile and install OpenCV and OpenAL. Thus you can - if needed - deselect the tab "Tools". |
||||||
|
The following steps assume that Qt is installed at "C:\Qt". If you decided to choose another location, replace corresponding parts. |
||||||
|
|
||||||
|
###MinGW |
||||||
|
|
||||||
|
Download the MinGW installer for Windows from [sourceforge.net](http://sourceforge.net/projects/mingw/files/Installer/). |
||||||
|
Make sure to install MSYS (a set of Unix tools for Windows). |
||||||
|
The following steps assume that MinGW is installed at "C:\MinGW". If you decided to choose another location, replace corresponding parts. |
||||||
|
|
||||||
|
###Setting up Path |
||||||
|
|
||||||
|
Add MinGW/MSYS binaries to the system path to make them globally accessible. |
||||||
|
Open Control Panel -> System and Security -> System -> Advanced system settings -> Environment Variables... |
||||||
|
In the second box search for the PATH variable and press Edit... |
||||||
|
The input box "Variable value:" should already contain some directories. Each directory is separated with a semicolon. |
||||||
|
Extend the input box by adding ";C:\MinGW\bin;C:\MinGW\msys\1.0\bin". The very first semicolon must only be added if it is missing. |
||||||
|
|
||||||
|
###Cloning the Repository |
||||||
|
|
||||||
|
Clone the repository (https://github.com/tux3/qTox.git) with your preferred Git client. [SmartGit](http://www.syntevo.com/smartgit/) is very nice for this task. |
||||||
|
The following steps assume that you cloned the repository at "C:\qTox". If you decided to choose another location, replace corresponding parts. |
||||||
|
|
||||||
|
###Tox Core |
||||||
|
|
||||||
|
[jenkins.libtoxcore.so](http://jenkins.libtoxcore.so/job/libtoxcore-win32-i686/lastSuccessfulBuild/artifact/libtoxcore-win32-i686.zip) |
||||||
|
provides a prebuild package of Tox Core. Download this package and extract its content to "C:\qTox\libs". You may have to create the directory "libs". |
||||||
|
If you prefer to compile Tox Core on your own follow the instructions at https://github.com/irungentoo/toxcore/blob/master/INSTALL.md#windows |
||||||
|
|
||||||
|
###OpenCV |
||||||
|
|
||||||
|
Unfortunately there are no prebuild packages for OpenCV compiled with MinGW. Thus, you have to create your own. |
||||||
|
First of all download and install the most recent version of CMake from |
||||||
|
[cmake.org](http://www.cmake.org/cmake/resources/software.html). |
||||||
|
Afterwards download OpenCV in version 2.4.9 from [sourceforge.net](http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download) and extract the content of the source archive to "C:\qTox\libs". Furthermore, create a new directory named "opencv-build" in "C:\qTox\libs". |
||||||
|
Now you should have the two directories "opencv-2.4.9" and "opencv-build" inside your "C:\qTox\libs" directory. |
||||||
|
|
||||||
|
Run CMake (cmake-gui) and set up the input boxes "Where is the source code:" and "Where to build the binaries" with "C:\qTox\libs\opencv-2.4.9" and "C:\qTox\libs\opencv-build". Press configure and choose "MSYS Makefiles" in the drop down menu with "Use default native compilers". To start initial configuration press Finish. Given that qTox only needs some components of OpenCV it's recommended to disable not required modules. Furthermore, this will decrease compilation time of OpenCV dramatically. Each module begins with "BUILD_opencv_" and can be disabled by deselecting its entry. Use the "Search" input box for convenience. Disable all modules except of "core", "highgui" and "imgproc" (highgui depends on imgproc and will automatically be disabled if imgproc is disabled). For maximum performance search for "CMAKE_BUILD_TYPE" and set this value to "Release". Finally, make sure "CMAKE_INSTALL_PREFIX" points to "C:\qTox\libs\opencv-build\install" (should be by default). To update the configuration press Configure again. To generate the Makefiles press Generate. |
||||||
|
|
||||||
|
Open a new command prompt within "C:\qTox\libs\opencv-build" (HINT: Use shift + right click -> "Open command window here" on the directory within Windows Explorer). Compile and install OpenCV with the following command. It's not recommended to use -j for multicore compilation, because it freezes the terminal from time to time. |
||||||
|
```bash |
||||||
|
make |
||||||
|
make install |
||||||
|
``` |
||||||
|
|
||||||
|
After OpenCV was successfully installed to "C:\qTox\libs\opencv-build\install" copy the dlls "libopencv_core249.dll", "libopencv_highgui249.dll" and "libopencv_imgproc249.dll" located at "C:\qTox\libs\opencv-build\install\x86\mingw\bin" to "C:\qTox\libs\lib". Afterwards copy the content of the directory "C:\qTox\libs\opencv-build\install\include" to "C:\qTox\libs\include". Finally, you have to patch the file "C:\qTox\libs\include\opencv2\opencv.hpp" because it includes all modules of OpenCV regardless of your configuration. Open this file with your preferred text editor and remove all includes except of "opencv2/core/core_c.h", "opencv2/core/core.hpp", "opencv2/imgproc/imgproc_c.h", "opencv2/imgproc/imgproc.hpp", "opencv2/highgui/highgui_c.h" and "opencv2/highgui/highgui.hpp". OpenCV is now ready to use. Feel free to delete the directories "opencv-2.4.9" and "opencv-build", but you don't need to. |
||||||
|
|
||||||
|
###OpenAL Soft |
||||||
|
As for OpenCV there are no prebuild packages of OpenAL Softe compiled with MinGW, but the installation process is very similar to OpenCV. Download the most recent source archive of OpenAL Soft from [http://kcat.strangesoft.net](http://kcat.strangesoft.net/openal.html#download). Extract its content to "C:\qTox\libs". Besides the source folder itself you'll find the file "pax_global_header". It is not required and can be deleted. Create the directory "openal-build" next to source folder. Now you should have the two directories "openal-soft-x.y.z" where x.y.z is the version of OpenAL and "openal-build" inside your "C:\qTox\libs" directory. Run CMake (cmake-gui) and setup the source and build location. Run the initial configuration and use "MSYS Makefiles" with "Use default native compilers". The only thing you need to configure is "CMAKE_INSTALL_PREFIX" which does not point to "C:\qTox\libs\openal-build\install" by default. Configure the project and generate the Makefiles. Compile and install OpenAL Soft with: |
||||||
|
```bash |
||||||
|
make |
||||||
|
make install |
||||||
|
``` |
||||||
|
Copy the dll "OpenAL32.dll" located at "C:\qTox\libs\openal-build\install\bin" to "C:\qTox\libs\lib". Finally, copy the directory "AL" located at "C:\qTox\libs\openal-build\install\include" to "C:\qTox\libs\include". Unlike OpenCV you don't need to patch any files. Feel free to delete the directories "openal-soft-x.y.z" and "openal-build", but you don't need to. |
||||||
|
|
||||||
|
##Linux |
||||||
|
Most of the dependencies should be available through your package manger. |
||||||
|
|
||||||
|
###Cloning the Repository |
||||||
|
In order to clone the qTox repository you need Git. |
||||||
|
|
||||||
|
Debian: |
||||||
|
```bash |
||||||
|
sudo apt-get install git |
||||||
|
``` |
||||||
|
|
||||||
|
Ubuntu: |
||||||
|
```bash |
||||||
|
sudo apt-get install git |
||||||
|
``` |
||||||
|
|
||||||
|
Arch Linux: |
||||||
|
```bash |
||||||
|
sudo pacman -S --needed git |
||||||
|
``` |
||||||
|
|
||||||
|
Fedora: |
||||||
|
```bash |
||||||
|
yum install git |
||||||
|
``` |
||||||
|
|
||||||
|
Afterwards open a new Terminal, change to a directory of your choice and clone the repository: |
||||||
|
```bash |
||||||
|
cd /home/user/qTox |
||||||
|
git clone https://github.com/tux3/qTox.git qTox |
||||||
|
``` |
||||||
|
|
||||||
|
The following steps assumes that you cloned the repository at "/home/user/qTox". If you decided to choose another location, replace corresponding parts. |
||||||
|
|
||||||
|
###GCC, Qt, OpenCV and OpanAL Soft |
||||||
|
|
||||||
|
Debian: |
||||||
|
```bash |
||||||
|
sudo apt-get install build-essential qt5-qmake qt5-default libopenal-dev libopencv-dev |
||||||
|
``` |
||||||
|
|
||||||
|
Ubuntu: |
||||||
|
```bash |
||||||
|
sudo apt-get install build-essential qt5-qmake qt5-default libopenal-dev libopencv-dev |
||||||
|
``` |
||||||
|
|
||||||
|
Arch Linux: |
||||||
|
```bash |
||||||
|
sudo pacman -S --needed base-devel qt5 opencv openal |
||||||
|
``` |
||||||
|
|
||||||
|
Fedora: |
||||||
|
```bash |
||||||
|
yum groupinstall "Development Tools" |
||||||
|
yum install qt-devel qt-doc qt-creator opencv-devel openal-soft-devel |
||||||
|
``` |
||||||
|
|
||||||
|
###Tox Core |
||||||
|
|
||||||
|
First of all install the dependencies of Tox Core. |
||||||
|
|
||||||
|
Debian: |
||||||
|
```bash |
||||||
|
sudo apt-get install libtool autotools-dev automake checkinstall check yasm libopus-dev libvpx-dev |
||||||
|
``` |
||||||
|
|
||||||
|
Ubuntu: |
||||||
|
```bash |
||||||
|
sudo apt-get install libtool autotools-dev automake checkinstall check yasm libopus-dev libvpx-dev |
||||||
|
``` |
||||||
|
|
||||||
|
Arch Linux: (Arch Linux provides the package "tox-git" in AUR) |
||||||
|
```bash |
||||||
|
sudo pacman -S --needed yasm opus vpx |
||||||
|
``` |
||||||
|
|
||||||
|
Fedora: |
||||||
|
```bash |
||||||
|
yum install libtool autoconf automake check check-devel |
||||||
|
``` |
||||||
|
|
||||||
|
Now you can either follow the instructions at https://github.com/irungentoo/toxcore/blob/master/INSTALL.md#unix or use the "bootstrap.sh" script located at "/home/user/qTox". |
||||||
|
The script will automatically download and install Tox Core and libsodium to "/home/user/qTox/libs": |
||||||
|
```bash |
||||||
|
cd /home/user/qTox |
||||||
|
./bootstrap.sh # use -h or --help for more information |
||||||
|
``` |
||||||
|
|
||||||
|
##Building packages |
||||||
|
|
||||||
|
qTox now has the experimental and probably-dodgy ability to package itself (in .deb |
||||||
|
form natively, and .rpm form with <a href="http://joeyh.name/code/alien/">alien</a>). |
||||||
|
|
||||||
|
After installing the required dependencies, run `bootstrap.sh` and then run the |
||||||
|
`buildPackages.sh` script, found in the tools folder. It will automatically get the |
||||||
|
packages necessary for building .debs, so be prepared to type your password for sudo. |
@ -0,0 +1,329 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "filetransferinstance.h" |
||||||
|
#include "widget/widget.h" |
||||||
|
#include "core.h" |
||||||
|
#include "math.h" |
||||||
|
#include "style.h" |
||||||
|
#include <QFileDialog> |
||||||
|
#include <QPixmap> |
||||||
|
#include <QPainter> |
||||||
|
#include <QMessageBox> |
||||||
|
#include <QBuffer> |
||||||
|
|
||||||
|
uint FileTransferInstance::Idconter = 0; |
||||||
|
|
||||||
|
FileTransferInstance::FileTransferInstance(ToxFile File) |
||||||
|
: lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0}, |
||||||
|
fileNum{File.fileNum}, friendId{File.friendId}, direction{File.direction} |
||||||
|
{ |
||||||
|
id = Idconter++; |
||||||
|
state = tsPending; |
||||||
|
|
||||||
|
filename = File.fileName; |
||||||
|
size = getHumanReadableSize(File.filesize); |
||||||
|
speed = "0B/s"; |
||||||
|
eta = "00:00"; |
||||||
|
if (File.direction == ToxFile::SENDING) |
||||||
|
{ |
||||||
|
QImage preview; |
||||||
|
File.file->seek(0); |
||||||
|
if (preview.loadFromData(File.file->readAll())) |
||||||
|
{ |
||||||
|
pic = preview.scaledToHeight(50); |
||||||
|
} |
||||||
|
File.file->seek(0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::getHumanReadableSize(unsigned long long size) |
||||||
|
{ |
||||||
|
static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"}; |
||||||
|
int exp = 0; |
||||||
|
if (size) |
||||||
|
exp = std::min( (int) (log(size) / log(1024)), (int) (sizeof(suffix) / sizeof(suffix[0]) - 1)); |
||||||
|
return QString().setNum(size / pow(1024, exp),'f',2).append(suffix[exp]); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction) |
||||||
|
{ |
||||||
|
if (FileNum != fileNum || FriendId != friendId || Direction != direction) |
||||||
|
return; |
||||||
|
|
||||||
|
state = tsProcessing; |
||||||
|
QDateTime newtime = QDateTime::currentDateTime(); |
||||||
|
int timediff = lastUpdate.secsTo(newtime); |
||||||
|
if (timediff <= 0) |
||||||
|
return; |
||||||
|
qint64 diff = BytesSent - lastBytesSent; |
||||||
|
if (diff < 0) |
||||||
|
{ |
||||||
|
qWarning() << "FileTransferInstance::onFileTransferInfo: Negative transfer speed !"; |
||||||
|
diff = 0; |
||||||
|
} |
||||||
|
long rawspeed = diff / timediff; |
||||||
|
speed = getHumanReadableSize(rawspeed)+"/s"; |
||||||
|
size = getHumanReadableSize(Filesize); |
||||||
|
if (!rawspeed) |
||||||
|
return; |
||||||
|
int etaSecs = (Filesize - BytesSent) / rawspeed; |
||||||
|
QTime etaTime(0,0); |
||||||
|
etaTime = etaTime.addSecs(etaSecs); |
||||||
|
eta = etaTime.toString("mm:ss"); |
||||||
|
lastUpdate = newtime; |
||||||
|
lastBytesSent = BytesSent; |
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::onFileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection Direction) |
||||||
|
{ |
||||||
|
if (FileNum != fileNum || FriendId != friendId || Direction != direction) |
||||||
|
return; |
||||||
|
disconnect(Widget::getInstance()->getCore(),0,this,0); |
||||||
|
state = tsCanceled; |
||||||
|
|
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::onFileTransferFinished(ToxFile File) |
||||||
|
{ |
||||||
|
if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction) |
||||||
|
return; |
||||||
|
disconnect(Widget::getInstance()->getCore(),0,this,0); |
||||||
|
|
||||||
|
if (File.direction == ToxFile::RECEIVING) |
||||||
|
{ |
||||||
|
QImage preview; |
||||||
|
QFile previewFile(File.filePath); |
||||||
|
if (previewFile.open(QIODevice::ReadOnly) && previewFile.size() <= 1024*1024*25) // Don't preview big (>25MiB) images
|
||||||
|
{ |
||||||
|
if (preview.loadFromData(previewFile.readAll())) |
||||||
|
{ |
||||||
|
pic = preview.scaledToHeight(50); |
||||||
|
} |
||||||
|
previewFile.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
state = tsFinished; |
||||||
|
|
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::cancelTransfer() |
||||||
|
{ |
||||||
|
Widget::getInstance()->getCore()->cancelFileSend(friendId, fileNum); |
||||||
|
state = tsCanceled; |
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::rejectRecvRequest() |
||||||
|
{ |
||||||
|
Widget::getInstance()->getCore()->rejectFileRecvRequest(friendId, fileNum); |
||||||
|
onFileTransferCancelled(friendId, fileNum, direction); |
||||||
|
state = tsCanceled; |
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
// for whatever the fuck reason, QFileInfo::isWritable() always fails for files that don't exist
|
||||||
|
// which makes it useless for our case
|
||||||
|
// since QDir doesn't have an isWritable(), the only option I can think of is to make/delete the file
|
||||||
|
// surely this is a common problem that has a qt-implemented solution?
|
||||||
|
bool isFileWritable(QString& path) |
||||||
|
{ |
||||||
|
QFile file(path); |
||||||
|
bool exists = file.exists(); |
||||||
|
bool out = file.open(QIODevice::WriteOnly); |
||||||
|
file.close(); |
||||||
|
if (!exists) |
||||||
|
file.remove(); |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::acceptRecvRequest() |
||||||
|
{ |
||||||
|
QString path; |
||||||
|
while (true) |
||||||
|
{ |
||||||
|
path = QFileDialog::getSaveFileName(Widget::getInstance(), tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename)); |
||||||
|
if (path.isEmpty()) |
||||||
|
return; |
||||||
|
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)) |
||||||
|
break; |
||||||
|
else |
||||||
|
QMessageBox::warning(Widget::getInstance(), 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; |
||||||
|
|
||||||
|
Widget::getInstance()->getCore()->acceptFileRecvRequest(friendId, fileNum, path); |
||||||
|
state = tsProcessing; |
||||||
|
|
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::pauseResumeRecv() |
||||||
|
{ |
||||||
|
Widget::getInstance()->getCore()->pauseResumeFileRecv(friendId, fileNum); |
||||||
|
if (state == tsProcessing) |
||||||
|
state = tsPaused; |
||||||
|
else state = tsProcessing; |
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::pauseResumeSend() |
||||||
|
{ |
||||||
|
Widget::getInstance()->getCore()->pauseResumeFileSend(friendId, fileNum); |
||||||
|
if (state == tsProcessing) |
||||||
|
state = tsPaused; |
||||||
|
else state = tsProcessing; |
||||||
|
emit stateUpdated(); |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::QImage2base64(const QImage &img) |
||||||
|
{ |
||||||
|
QByteArray ba; |
||||||
|
QBuffer buffer(&ba); |
||||||
|
buffer.open(QIODevice::WriteOnly); |
||||||
|
img.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||||
|
return ba.toBase64(); |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::getHtmlImage() |
||||||
|
{ |
||||||
|
qDebug() << "QString FileTransferInstance::getHtmlImage() " << state; |
||||||
|
|
||||||
|
QString res; |
||||||
|
if (state == tsPending || state == tsProcessing || state == tsPaused) |
||||||
|
{ |
||||||
|
QImage leftBtnImg(":/ui/fileTransferInstance/stopFileButton.png"); |
||||||
|
QImage rightBtnImg; |
||||||
|
if (state == tsProcessing) |
||||||
|
rightBtnImg = QImage(":/ui/fileTransferInstance/pauseFileButton.png"); |
||||||
|
else if (state == tsPaused) |
||||||
|
rightBtnImg = QImage(":/ui/fileTransferInstance/resumeFileButton.png"); |
||||||
|
else |
||||||
|
rightBtnImg = QImage(":/ui/fileTransferInstance/acceptFileButton.png"); |
||||||
|
|
||||||
|
res = draw2ButtonsForm("silver", leftBtnImg, rightBtnImg); |
||||||
|
} else if (state == tsCanceled) |
||||||
|
{ |
||||||
|
res = drawButtonlessForm("red"); |
||||||
|
} else if (state == tsFinished) |
||||||
|
{ |
||||||
|
res = drawButtonlessForm("green"); |
||||||
|
} |
||||||
|
|
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
void FileTransferInstance::pressFromHtml(QString code) |
||||||
|
{ |
||||||
|
if (state == tsFinished || state == tsCanceled) |
||||||
|
return; |
||||||
|
|
||||||
|
if (direction == ToxFile::SENDING) |
||||||
|
{ |
||||||
|
if (code == "btnA") |
||||||
|
cancelTransfer(); |
||||||
|
else if (code == "btnB") |
||||||
|
pauseResumeSend(); |
||||||
|
} else { |
||||||
|
if (code == "btnA") |
||||||
|
rejectRecvRequest(); |
||||||
|
else if (code == "btnB") |
||||||
|
{ |
||||||
|
if (state == tsPending) |
||||||
|
acceptRecvRequest(); |
||||||
|
else |
||||||
|
pauseResumeRecv(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::drawButtonlessForm(const QString &type) |
||||||
|
{ |
||||||
|
QString imgAStr; |
||||||
|
QString imgBStr; |
||||||
|
|
||||||
|
if (type == "red") |
||||||
|
{ |
||||||
|
imgAStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLRedFileButton.png")) + "\">"; |
||||||
|
imgBStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyRRedFileButton.png")) + "\">"; |
||||||
|
} else { |
||||||
|
imgAStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLGreenFileButton.png")) + "\">"; |
||||||
|
imgBStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyRGreenFileButton.png")) + "\">"; |
||||||
|
} |
||||||
|
|
||||||
|
QString content = "<p>" + filename + "</p><p>" + size + "</p>"; |
||||||
|
|
||||||
|
return wrapIntoForm(content, type, imgAStr, imgBStr); |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::insertMiniature(const QString &type) |
||||||
|
{ |
||||||
|
if (pic == QImage()) |
||||||
|
return QString(); |
||||||
|
|
||||||
|
QString widgetId = QString::number(getId()); |
||||||
|
|
||||||
|
QString res; |
||||||
|
res = "<td><div class=" + type + ">\n"; |
||||||
|
res += "<img src=\"data:mini." + widgetId + "/png;base64," + QImage2base64(pic) + "\">"; |
||||||
|
res += "</div></td>\n"; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::draw2ButtonsForm(const QString &type, const QImage &imgA, const QImage &imgB) |
||||||
|
{ |
||||||
|
QString widgetId = QString::number(getId()); |
||||||
|
QString imgAstr = "<img src=\"data:ftrans." + widgetId + ".btnA/png;base64," + QImage2base64(imgA) + "\">"; |
||||||
|
QString imgBstr = "<img src=\"data:ftrans." + widgetId + ".btnB/png;base64," + QImage2base64(imgB) + "\">"; |
||||||
|
|
||||||
|
QString content; |
||||||
|
content += "<p>" + filename + "</p>"; |
||||||
|
content += "<p>" + getHumanReadableSize(lastBytesSent) + " / " + size + " (" + speed + " ETA: " + eta + ")</p>\n"; |
||||||
|
|
||||||
|
return wrapIntoForm(content, type, imgAstr, imgBstr); |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferInstance::wrapIntoForm(const QString& content, const QString &type, const QString &imgAstr, const QString &imgBstr) |
||||||
|
{ |
||||||
|
QString res; |
||||||
|
|
||||||
|
res = "<table widht=100% cellspacing=\"0\">\n"; |
||||||
|
res += "<tr valign=middle>\n"; |
||||||
|
res += insertMiniature(type); |
||||||
|
res += "<td width=100%>\n"; |
||||||
|
res += "<div class=" + type + ">"; |
||||||
|
res += content; |
||||||
|
res += "</div>\n"; |
||||||
|
res += "</td>\n"; |
||||||
|
res += "<td>\n"; |
||||||
|
res += "<div class=button>" + imgAstr + "<br>" + imgBstr+ "</div>\n"; |
||||||
|
res += "</td>\n"; |
||||||
|
res += "</tr>\n"; |
||||||
|
res += "</table>\n"; |
||||||
|
|
||||||
|
return res; |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
div.name_me { |
||||||
|
color: #646464; |
||||||
|
font-weight: bold; |
||||||
|
padding-right: 3px; |
||||||
|
} |
||||||
|
|
||||||
|
div.name { |
||||||
|
color: #000000; |
||||||
|
font-weight: bold; |
||||||
|
padding-right: 3px; |
||||||
|
} |
||||||
|
|
||||||
|
div.message { |
||||||
|
color: #000000; |
||||||
|
padding-right: 3px; |
||||||
|
padding-left: 3px; |
||||||
|
} |
||||||
|
|
||||||
|
div.date { |
||||||
|
color: #000000; |
||||||
|
padding-left: 3px; |
||||||
|
white-space: nowrap; |
||||||
|
} |
||||||
|
|
||||||
|
div.quote { |
||||||
|
background-color: #6bc260; |
||||||
|
} |
||||||
|
|
||||||
|
div.green { |
||||||
|
margin-top: 12px; |
||||||
|
margin-bottom: 12px; |
||||||
|
margin-left: 12px; |
||||||
|
margin-right: 12px; |
||||||
|
color: #ffffff; |
||||||
|
background-color: #6bc260; |
||||||
|
font-size: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
div.silver { |
||||||
|
margin-top: 12px; |
||||||
|
margin-bottom: 12px; |
||||||
|
margin-left: 12px; |
||||||
|
margin-right: 12px; |
||||||
|
color: #000000; |
||||||
|
background-color: #d1d1d1; |
||||||
|
font-size: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
div.red { |
||||||
|
margin-top: 12px; |
||||||
|
margin-bottom: 12px; |
||||||
|
margin-left: 12px; |
||||||
|
margin-right: 12px; |
||||||
|
color: #ffffff; |
||||||
|
background-color: rgb(200,78,78); |
||||||
|
font-size: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
div.button { |
||||||
|
margin-top: 0px; |
||||||
|
margin-bottom: 0px; |
||||||
|
margin-left: 0px; |
||||||
|
color: #ffffff; |
||||||
|
} |
After Width: | Height: | Size: 457 B |
After Width: | Height: | Size: 449 B |
After Width: | Height: | Size: 236 B |
After Width: | Height: | Size: 229 B |
After Width: | Height: | Size: 216 B |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 308 B |
After Width: | Height: | Size: 244 B |
After Width: | Height: | Size: 516 B |
@ -0,0 +1,112 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "chatareawidget.h" |
||||||
|
#include <QAbstractTextDocumentLayout> |
||||||
|
#include <QMessageBox> |
||||||
|
#include <QScrollBar> |
||||||
|
|
||||||
|
ChatAreaWidget::ChatAreaWidget(QWidget *parent) : |
||||||
|
QTextEdit(parent) |
||||||
|
{ |
||||||
|
setReadOnly(true); |
||||||
|
viewport()->setCursor(Qt::ArrowCursor); |
||||||
|
setContextMenuPolicy(Qt::CustomContextMenu); |
||||||
|
setUndoRedoEnabled(false); |
||||||
|
} |
||||||
|
|
||||||
|
ChatAreaWidget::~ChatAreaWidget() |
||||||
|
{ |
||||||
|
for (ChatAction *it : messages) |
||||||
|
delete it; |
||||||
|
} |
||||||
|
|
||||||
|
void ChatAreaWidget::mouseReleaseEvent(QMouseEvent * event) |
||||||
|
{ |
||||||
|
QTextEdit::mouseReleaseEvent(event); |
||||||
|
int pos = this->document()->documentLayout()->hitTest(event->pos(), Qt::ExactHit); |
||||||
|
if (pos > 0) |
||||||
|
{ |
||||||
|
QTextCursor cursor(document()); |
||||||
|
cursor.setPosition(pos); |
||||||
|
if( ! cursor.atEnd() ) |
||||||
|
{ |
||||||
|
cursor.setPosition(pos+1); |
||||||
|
|
||||||
|
QTextFormat format = cursor.charFormat(); |
||||||
|
if (format.isImageFormat()) |
||||||
|
{ |
||||||
|
QString imageName = format.toImageFormat().name(); |
||||||
|
if (QRegExp("^data:ftrans.*").exactMatch(imageName)) |
||||||
|
{ |
||||||
|
QString data = imageName.right(imageName.length() - 12); |
||||||
|
int endpos = data.indexOf("/png;base64"); |
||||||
|
data = data.left(endpos); |
||||||
|
int middlepos = data.indexOf("."); |
||||||
|
QString widgetID = data.left(middlepos); |
||||||
|
QString widgetBtn = data.right(data.length() - middlepos - 1); |
||||||
|
emit onFileTranfertInterract(widgetID, widgetBtn); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAreaWidget::getHtmledMessages() |
||||||
|
{ |
||||||
|
QString res("<table width=100%>\n"); |
||||||
|
|
||||||
|
for (ChatAction *it : messages) |
||||||
|
{ |
||||||
|
res += it->getHtml(); |
||||||
|
} |
||||||
|
res += "</table>"; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
void ChatAreaWidget::insertMessage(ChatAction *msgAction) |
||||||
|
{ |
||||||
|
if (msgAction == nullptr) |
||||||
|
return; |
||||||
|
|
||||||
|
messages.append(msgAction); |
||||||
|
//updateChatContent();
|
||||||
|
|
||||||
|
moveCursor(QTextCursor::End); |
||||||
|
moveCursor(QTextCursor::PreviousCell); |
||||||
|
insertHtml(msgAction->getHtml()); |
||||||
|
} |
||||||
|
|
||||||
|
void ChatAreaWidget::updateChatContent() |
||||||
|
{ |
||||||
|
QScrollBar* scroll = verticalScrollBar(); |
||||||
|
lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); |
||||||
|
|
||||||
|
setUpdatesEnabled(false); |
||||||
|
setHtml(getHtmledMessages()); |
||||||
|
setUpdatesEnabled(true); |
||||||
|
if (lockSliderToBottom) |
||||||
|
sliderPosition = scroll->maximum(); |
||||||
|
|
||||||
|
scroll->setValue(sliderPosition); |
||||||
|
} |
||||||
|
|
||||||
|
void ChatAreaWidget::clearMessages() |
||||||
|
{ |
||||||
|
for (ChatAction *it : messages) |
||||||
|
delete it; |
||||||
|
updateChatContent(); |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef CHATAREAWIDGET_H |
||||||
|
#define CHATAREAWIDGET_H |
||||||
|
|
||||||
|
#include <QTextEdit> |
||||||
|
#include <QList> |
||||||
|
#include "widget/tool/chataction.h" |
||||||
|
|
||||||
|
class ChatAreaWidget : public QTextEdit |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit ChatAreaWidget(QWidget *parent = 0); |
||||||
|
virtual ~ChatAreaWidget(); |
||||||
|
void insertMessage(ChatAction *msgAction); |
||||||
|
void clearMessages(); |
||||||
|
|
||||||
|
signals: |
||||||
|
void onFileTranfertInterract(QString widgetName, QString buttonName); |
||||||
|
|
||||||
|
protected: |
||||||
|
void mouseReleaseEvent(QMouseEvent * event); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void updateChatContent(); |
||||||
|
|
||||||
|
private: |
||||||
|
QString getHtmledMessages(); |
||||||
|
QList<ChatAction*> messages; |
||||||
|
bool lockSliderToBottom; |
||||||
|
int sliderPosition; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // CHATAREAWIDGET_H
|
@ -1,320 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
||||||
|
|
||||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
|
||||||
|
|
||||||
This program is libre software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||||
|
|
||||||
See the COPYING file for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "filetransfertwidget.h" |
|
||||||
#include "widget.h" |
|
||||||
#include "core.h" |
|
||||||
#include "math.h" |
|
||||||
#include "style.h" |
|
||||||
#include <QFileDialog> |
|
||||||
#include <QPixmap> |
|
||||||
#include <QPainter> |
|
||||||
#include <QMessageBox> |
|
||||||
|
|
||||||
FileTransfertWidget::FileTransfertWidget(ToxFile File) |
|
||||||
: lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0}, |
|
||||||
fileNum{File.fileNum}, friendId{File.friendId}, direction{File.direction} |
|
||||||
{ |
|
||||||
pic=new QLabel(), filename=new QLabel(), size=new QLabel(), speed=new QLabel(), eta=new QLabel(); |
|
||||||
topright = new QPushButton(), bottomright = new QPushButton(); |
|
||||||
progress = new QProgressBar(); |
|
||||||
mainLayout = new QHBoxLayout(), textLayout = new QHBoxLayout(); |
|
||||||
infoLayout = new QVBoxLayout(), buttonLayout = new QVBoxLayout(); |
|
||||||
buttonWidget = new QWidget(); |
|
||||||
QFont prettysmall; |
|
||||||
prettysmall.setPixelSize(10); |
|
||||||
this->setObjectName("default"); |
|
||||||
this->setStyleSheet(Style::get(":/ui/fileTransferWidget/fileTransferWidget.css")); |
|
||||||
QPalette greybg; |
|
||||||
greybg.setColor(QPalette::Window, QColor(209,209,209)); |
|
||||||
greybg.setColor(QPalette::Base, QColor(150,150,150)); |
|
||||||
setPalette(greybg); |
|
||||||
setAutoFillBackground(true); |
|
||||||
|
|
||||||
setMinimumSize(250,58); |
|
||||||
setMaximumHeight(58); |
|
||||||
setLayout(mainLayout); |
|
||||||
mainLayout->setMargin(0); |
|
||||||
|
|
||||||
pic->setMaximumHeight(40); |
|
||||||
pic->setContentsMargins(5,0,0,0); |
|
||||||
filename->setText(File.fileName); |
|
||||||
filename->setFont(prettysmall); |
|
||||||
size->setText(getHumanReadableSize(File.filesize)); |
|
||||||
size->setFont(prettysmall); |
|
||||||
speed->setText("0B/s"); |
|
||||||
speed->setFont(prettysmall); |
|
||||||
eta->setText("00:00"); |
|
||||||
eta->setFont(prettysmall); |
|
||||||
progress->setValue(0); |
|
||||||
progress->setMinimumHeight(11); |
|
||||||
progress->setFont(prettysmall); |
|
||||||
progress->setTextVisible(false); |
|
||||||
QPalette whitebg; |
|
||||||
whitebg.setColor(QPalette::Window, QColor(255,255,255)); |
|
||||||
buttonWidget->setPalette(whitebg); |
|
||||||
buttonWidget->setAutoFillBackground(true); |
|
||||||
buttonWidget->setLayout(buttonLayout); |
|
||||||
|
|
||||||
stopFileButtonStylesheet = Style::get(":/ui/stopFileButton/style.css"); |
|
||||||
pauseFileButtonStylesheet = Style::get(":/ui/pauseFileButton/style.css"); |
|
||||||
acceptFileButtonStylesheet = Style::get(":/ui/acceptFileButton/style.css"); |
|
||||||
|
|
||||||
topright->setStyleSheet(stopFileButtonStylesheet); |
|
||||||
if (File.direction == ToxFile::SENDING) |
|
||||||
{ |
|
||||||
bottomright->setStyleSheet(pauseFileButtonStylesheet); |
|
||||||
connect(topright, SIGNAL(clicked()), this, SLOT(cancelTransfer())); |
|
||||||
connect(bottomright, SIGNAL(clicked()), this, SLOT(pauseResumeSend())); |
|
||||||
|
|
||||||
QPixmap preview; |
|
||||||
File.file->seek(0); |
|
||||||
if (preview.loadFromData(File.file->readAll())) |
|
||||||
{ |
|
||||||
preview = preview.scaledToHeight(40); |
|
||||||
pic->setPixmap(preview); |
|
||||||
} |
|
||||||
File.file->seek(0); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
bottomright->setStyleSheet(acceptFileButtonStylesheet); |
|
||||||
connect(topright, SIGNAL(clicked()), this, SLOT(rejectRecvRequest())); |
|
||||||
connect(bottomright, SIGNAL(clicked()), this, SLOT(acceptRecvRequest())); |
|
||||||
} |
|
||||||
|
|
||||||
QPalette toxgreen; |
|
||||||
toxgreen.setColor(QPalette::Button, QColor(107,194,96)); // Tox Green
|
|
||||||
topright->setIconSize(QSize(10,10)); |
|
||||||
topright->setMinimumSize(25,28); |
|
||||||
topright->setFlat(true); |
|
||||||
topright->setAutoFillBackground(true); |
|
||||||
topright->setPalette(toxgreen); |
|
||||||
bottomright->setIconSize(QSize(10,10)); |
|
||||||
bottomright->setMinimumSize(25,28); |
|
||||||
bottomright->setFlat(true); |
|
||||||
bottomright->setAutoFillBackground(true); |
|
||||||
bottomright->setPalette(toxgreen); |
|
||||||
|
|
||||||
mainLayout->addStretch(); |
|
||||||
mainLayout->addWidget(pic); |
|
||||||
mainLayout->addLayout(infoLayout,3); |
|
||||||
mainLayout->addStretch(); |
|
||||||
mainLayout->addWidget(buttonWidget); |
|
||||||
mainLayout->setMargin(0); |
|
||||||
mainLayout->setSpacing(0); |
|
||||||
|
|
||||||
infoLayout->addWidget(filename); |
|
||||||
infoLayout->addLayout(textLayout); |
|
||||||
infoLayout->addWidget(progress); |
|
||||||
infoLayout->setMargin(4); |
|
||||||
infoLayout->setSpacing(4); |
|
||||||
|
|
||||||
textLayout->addWidget(size); |
|
||||||
textLayout->addStretch(0); |
|
||||||
textLayout->addWidget(speed); |
|
||||||
textLayout->addStretch(0); |
|
||||||
textLayout->addWidget(eta); |
|
||||||
textLayout->setMargin(2); |
|
||||||
textLayout->setSpacing(5); |
|
||||||
|
|
||||||
buttonLayout->addWidget(topright); |
|
||||||
buttonLayout->addSpacing(2); |
|
||||||
buttonLayout->addWidget(bottomright); |
|
||||||
buttonLayout->setContentsMargins(2,0,0,0); |
|
||||||
buttonLayout->setSpacing(0); |
|
||||||
} |
|
||||||
|
|
||||||
QString FileTransfertWidget::getHumanReadableSize(unsigned long long size) |
|
||||||
{ |
|
||||||
static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"}; |
|
||||||
int exp = 0; |
|
||||||
if (size) |
|
||||||
exp = std::min( (int) (log(size) / log(1024)), (int) (sizeof(suffix) / sizeof(suffix[0]) - 1)); |
|
||||||
return QString().setNum(size / pow(1024, exp),'f',2).append(suffix[exp]); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction) |
|
||||||
{ |
|
||||||
if (FileNum != fileNum || FriendId != friendId || Direction != direction) |
|
||||||
return; |
|
||||||
QDateTime newtime = QDateTime::currentDateTime(); |
|
||||||
int timediff = lastUpdate.secsTo(newtime); |
|
||||||
if (timediff <= 0) |
|
||||||
return; |
|
||||||
qint64 diff = BytesSent - lastBytesSent; |
|
||||||
if (diff < 0) |
|
||||||
{ |
|
||||||
qWarning() << "FileTransfertWidget::onFileTransferInfo: Negative transfer speed !"; |
|
||||||
diff = 0; |
|
||||||
} |
|
||||||
long rawspeed = diff / timediff; |
|
||||||
speed->setText(getHumanReadableSize(rawspeed)+"/s"); |
|
||||||
size->setText(getHumanReadableSize(Filesize)); |
|
||||||
if (!rawspeed) |
|
||||||
return; |
|
||||||
int etaSecs = (Filesize - BytesSent) / rawspeed; |
|
||||||
QTime etaTime(0,0); |
|
||||||
etaTime = etaTime.addSecs(etaSecs); |
|
||||||
eta->setText(etaTime.toString("mm:ss")); |
|
||||||
if (!Filesize) |
|
||||||
{ |
|
||||||
progress->setValue(0); |
|
||||||
qDebug() << QString("FT: received %1 bytes of an empty file, stop sending sequential devices, zetok!").arg(BytesSent); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
progress->setValue(BytesSent*100/Filesize); |
|
||||||
qDebug() << QString("FT: received %1/%2 bytes, progress is %3%").arg(BytesSent).arg(Filesize).arg(BytesSent*100/Filesize); |
|
||||||
} |
|
||||||
lastUpdate = newtime; |
|
||||||
lastBytesSent = BytesSent; |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::onFileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection Direction) |
|
||||||
{ |
|
||||||
if (FileNum != fileNum || FriendId != friendId || Direction != direction) |
|
||||||
return; |
|
||||||
buttonLayout->setContentsMargins(0,0,0,0); |
|
||||||
disconnect(topright); |
|
||||||
disconnect(Widget::getInstance()->getCore(),0,this,0); |
|
||||||
progress->hide(); |
|
||||||
speed->hide(); |
|
||||||
eta->hide(); |
|
||||||
topright->hide(); |
|
||||||
bottomright->hide(); |
|
||||||
QPalette whiteText; |
|
||||||
whiteText.setColor(QPalette::WindowText, Qt::white); |
|
||||||
filename->setPalette(whiteText); |
|
||||||
size->setPalette(whiteText); |
|
||||||
this->setObjectName("error"); |
|
||||||
this->style()->polish(this); |
|
||||||
|
|
||||||
//Toggle window visibility to fix draw order bug
|
|
||||||
this->hide(); |
|
||||||
this->show(); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::onFileTransferFinished(ToxFile File) |
|
||||||
{ |
|
||||||
if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction) |
|
||||||
return; |
|
||||||
topright->disconnect(); |
|
||||||
disconnect(Widget::getInstance()->getCore(),0,this,0); |
|
||||||
progress->hide(); |
|
||||||
speed->hide(); |
|
||||||
eta->hide(); |
|
||||||
topright->hide(); |
|
||||||
bottomright->hide(); |
|
||||||
buttonLayout->setContentsMargins(0,0,0,0); |
|
||||||
QPalette whiteText; |
|
||||||
whiteText.setColor(QPalette::WindowText, Qt::white); |
|
||||||
filename->setPalette(whiteText); |
|
||||||
size->setPalette(whiteText); |
|
||||||
this->setObjectName("success"); |
|
||||||
this->style()->polish(this); |
|
||||||
|
|
||||||
//Toggle window visibility to fix draw order bug
|
|
||||||
this->hide(); |
|
||||||
this->show(); |
|
||||||
|
|
||||||
if (File.direction == ToxFile::RECEIVING) |
|
||||||
{ |
|
||||||
QPixmap preview; |
|
||||||
QFile previewFile(File.filePath); |
|
||||||
if (previewFile.open(QIODevice::ReadOnly) && previewFile.size() <= 1024*1024*25) // Don't preview big (>25MiB) images
|
|
||||||
{ |
|
||||||
if (preview.loadFromData(previewFile.readAll())) |
|
||||||
{ |
|
||||||
preview = preview.scaledToHeight(40); |
|
||||||
pic->setPixmap(preview); |
|
||||||
} |
|
||||||
previewFile.close(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::cancelTransfer() |
|
||||||
{ |
|
||||||
Widget::getInstance()->getCore()->cancelFileSend(friendId, fileNum); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::rejectRecvRequest() |
|
||||||
{ |
|
||||||
Widget::getInstance()->getCore()->rejectFileRecvRequest(friendId, fileNum); |
|
||||||
onFileTransferCancelled(friendId, fileNum, direction); |
|
||||||
} |
|
||||||
|
|
||||||
// for whatever the fuck reason, QFileInfo::isWritable() always fails for files that don't exist
|
|
||||||
// which makes it useless for our case
|
|
||||||
// since QDir doesn't have an isWritable(), the only option I can think of is to make/delete the file
|
|
||||||
// surely this is a common problem that has a qt-implemented solution?
|
|
||||||
bool isWritable(QString& path) |
|
||||||
{ |
|
||||||
QFile file(path); |
|
||||||
bool exists = file.exists(); |
|
||||||
bool out = file.open(QIODevice::WriteOnly); |
|
||||||
file.close(); |
|
||||||
if (!exists) |
|
||||||
file.remove(); |
|
||||||
return out; |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::acceptRecvRequest() |
|
||||||
{ |
|
||||||
QString path; |
|
||||||
while (true) |
|
||||||
{ |
|
||||||
path = QFileDialog::getSaveFileName(this, tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename->text())); |
|
||||||
if (path.isEmpty()) |
|
||||||
return; |
|
||||||
else |
|
||||||
{ |
|
||||||
//bool savable = QFileInfo(path).isWritable();
|
|
||||||
//qDebug() << path << " is writable: " << savable;
|
|
||||||
//qDebug() << "/home/bill/bliss.pdf writable: " << QFileInfo("/home/bill/bliss.pdf").isWritable();
|
|
||||||
if (isWritable(path)) |
|
||||||
break; |
|
||||||
else |
|
||||||
QMessageBox::warning(this, 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; |
|
||||||
|
|
||||||
bottomright->setStyleSheet(pauseFileButtonStylesheet); |
|
||||||
bottomright->disconnect(); |
|
||||||
connect(bottomright, SIGNAL(clicked()), this, SLOT(pauseResumeRecv())); |
|
||||||
Widget::getInstance()->getCore()->acceptFileRecvRequest(friendId, fileNum, path); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::pauseResumeRecv() |
|
||||||
{ |
|
||||||
Widget::getInstance()->getCore()->pauseResumeFileRecv(friendId, fileNum); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::pauseResumeSend() |
|
||||||
{ |
|
||||||
Widget::getInstance()->getCore()->pauseResumeFileSend(friendId, fileNum); |
|
||||||
} |
|
||||||
|
|
||||||
void FileTransfertWidget::paintEvent(QPaintEvent *) |
|
||||||
{ |
|
||||||
QStyleOption opt; |
|
||||||
opt.init(this); |
|
||||||
QPainter p(this); |
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); |
|
||||||
} |
|
@ -0,0 +1,202 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "genericchatform.h" |
||||||
|
#include "ui_mainwindow.h" |
||||||
|
#include <QFileDialog> |
||||||
|
#include "smileypack.h" |
||||||
|
#include "widget/emoticonswidget.h" |
||||||
|
#include "style.h" |
||||||
|
#include "widget/widget.h" |
||||||
|
#include "settings.h" |
||||||
|
|
||||||
|
GenericChatForm::GenericChatForm(QObject *parent) : |
||||||
|
QObject(parent) |
||||||
|
{ |
||||||
|
curRow = 0; |
||||||
|
|
||||||
|
mainWidget = new QWidget(); headWidget = new QWidget(); |
||||||
|
|
||||||
|
nameLabel = new CroppingLabel(); |
||||||
|
avatarLabel = new QLabel(); |
||||||
|
QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout(); |
||||||
|
headTextLayout = new QVBoxLayout(); |
||||||
|
QVBoxLayout *mainLayout = new QVBoxLayout(); |
||||||
|
QVBoxLayout *footButtonsSmall = new QVBoxLayout(), *volMicLayout = new QVBoxLayout(); |
||||||
|
|
||||||
|
chatWidget = new ChatAreaWidget(); |
||||||
|
chatWidget->document()->setDefaultStyleSheet(Style::get(":ui/chatArea/innerStyle.css")); |
||||||
|
chatWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css")); |
||||||
|
|
||||||
|
msgEdit = new ChatTextEdit(); |
||||||
|
|
||||||
|
sendButton = new QPushButton(); |
||||||
|
emoteButton = new QPushButton(); |
||||||
|
|
||||||
|
fileButton = new QPushButton(); |
||||||
|
callButton = new QPushButton(); |
||||||
|
videoButton = new QPushButton(); |
||||||
|
volButton = new QPushButton(); |
||||||
|
micButton = new QPushButton(); |
||||||
|
|
||||||
|
QFont bold; |
||||||
|
bold.setBold(true); |
||||||
|
nameLabel->setFont(bold); |
||||||
|
|
||||||
|
footButtonsSmall->setSpacing(2); |
||||||
|
|
||||||
|
msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css")); |
||||||
|
msgEdit->setFixedHeight(50); |
||||||
|
msgEdit->setFrameStyle(QFrame::NoFrame); |
||||||
|
|
||||||
|
sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css")); |
||||||
|
fileButton->setStyleSheet(Style::get(":/ui/fileButton/fileButton.css")); |
||||||
|
emoteButton->setStyleSheet(Style::get(":/ui/emoteButton/emoteButton.css")); |
||||||
|
|
||||||
|
callButton->setObjectName("green"); |
||||||
|
callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css")); |
||||||
|
|
||||||
|
videoButton->setObjectName("green"); |
||||||
|
videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css")); |
||||||
|
|
||||||
|
QString volButtonStylesheet = Style::get(":/ui/volButton/volButton.css"); |
||||||
|
volButton->setObjectName("green"); |
||||||
|
volButton->setStyleSheet(volButtonStylesheet); |
||||||
|
|
||||||
|
QString micButtonStylesheet = Style::get(":/ui/micButton/micButton.css"); |
||||||
|
micButton->setObjectName("green"); |
||||||
|
micButton->setStyleSheet(micButtonStylesheet); |
||||||
|
|
||||||
|
mainWidget->setLayout(mainLayout); |
||||||
|
mainLayout->addWidget(chatWidget); |
||||||
|
mainLayout->addLayout(mainFootLayout); |
||||||
|
mainLayout->setMargin(0); |
||||||
|
|
||||||
|
footButtonsSmall->addWidget(emoteButton); |
||||||
|
footButtonsSmall->addWidget(fileButton); |
||||||
|
|
||||||
|
mainFootLayout->addWidget(msgEdit); |
||||||
|
mainFootLayout->addLayout(footButtonsSmall); |
||||||
|
mainFootLayout->addSpacing(5); |
||||||
|
mainFootLayout->addWidget(sendButton); |
||||||
|
mainFootLayout->setSpacing(0); |
||||||
|
|
||||||
|
headWidget->setLayout(headLayout); |
||||||
|
headLayout->addWidget(avatarLabel); |
||||||
|
headLayout->addLayout(headTextLayout); |
||||||
|
headLayout->addLayout(volMicLayout); |
||||||
|
headLayout->addWidget(callButton); |
||||||
|
headLayout->addWidget(videoButton); |
||||||
|
|
||||||
|
volMicLayout->addWidget(micButton); |
||||||
|
volMicLayout->addWidget(volButton); |
||||||
|
|
||||||
|
headTextLayout->addStretch(); |
||||||
|
headTextLayout->addWidget(nameLabel); |
||||||
|
|
||||||
|
//Fix for incorrect layouts on OS X as per
|
||||||
|
//https://bugreports.qt-project.org/browse/QTBUG-14591
|
||||||
|
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); |
||||||
|
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); |
||||||
|
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); |
||||||
|
|
||||||
|
connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked())); |
||||||
|
connect(chatWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::setName(const QString &newName) |
||||||
|
{ |
||||||
|
nameLabel->setText(newName); |
||||||
|
nameLabel->setToolTip(newName); // for overlength names
|
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::show(Ui::MainWindow &ui) |
||||||
|
{ |
||||||
|
ui.mainContent->layout()->addWidget(mainWidget); |
||||||
|
ui.mainHead->layout()->addWidget(headWidget); |
||||||
|
mainWidget->show(); |
||||||
|
headWidget->show(); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::onChatContextMenuRequested(QPoint pos) |
||||||
|
{ |
||||||
|
QWidget* sender = (QWidget*)QObject::sender(); |
||||||
|
pos = sender->mapToGlobal(pos); |
||||||
|
QMenu menu; |
||||||
|
menu.addAction(tr("Save chat log"), this, SLOT(onSaveLogClicked())); |
||||||
|
menu.exec(pos); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::onSaveLogClicked() |
||||||
|
{ |
||||||
|
QString path = QFileDialog::getSaveFileName(0, tr("Save chat log")); |
||||||
|
if (path.isEmpty()) |
||||||
|
return; |
||||||
|
|
||||||
|
QFile file(path); |
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) |
||||||
|
return; |
||||||
|
|
||||||
|
QString log; |
||||||
|
log = chatWidget->toPlainText(); |
||||||
|
|
||||||
|
file.write(log.toUtf8()); |
||||||
|
file.close(); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::addMessage(QString author, QString message, QDateTime datetime) |
||||||
|
{ |
||||||
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); |
||||||
|
bool isMe = (author == Widget::getInstance()->getUsername()); |
||||||
|
|
||||||
|
if (previousName == author) |
||||||
|
chatWidget->insertMessage(new MessageAction("", message, date, isMe)); |
||||||
|
else chatWidget->insertMessage(new MessageAction(author , message, date, isMe)); |
||||||
|
previousName = author; |
||||||
|
} |
||||||
|
|
||||||
|
GenericChatForm::~GenericChatForm() |
||||||
|
{ |
||||||
|
delete mainWidget; |
||||||
|
delete headWidget; |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::onEmoteButtonClicked() |
||||||
|
{ |
||||||
|
// don't show the smiley selection widget if there are no smileys available
|
||||||
|
if (SmileyPack::getInstance().getEmoticons().empty()) |
||||||
|
return; |
||||||
|
|
||||||
|
EmoticonsWidget widget; |
||||||
|
connect(&widget, SIGNAL(insertEmoticon(QString)), this, SLOT(onEmoteInsertRequested(QString))); |
||||||
|
|
||||||
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender()); |
||||||
|
if (sender) |
||||||
|
{ |
||||||
|
QPoint pos = -QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height()) - QPoint(0, 10); |
||||||
|
widget.exec(sender->mapToGlobal(pos)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void GenericChatForm::onEmoteInsertRequested(QString str) |
||||||
|
{ |
||||||
|
// insert the emoticon
|
||||||
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender()); |
||||||
|
if (sender) |
||||||
|
msgEdit->insertPlainText(str); |
||||||
|
|
||||||
|
msgEdit->setFocus(); // refocus so that we can continue typing
|
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GENERICCHATFORM_H |
||||||
|
#define GENERICCHATFORM_H |
||||||
|
|
||||||
|
#include <QObject> |
||||||
|
#include <QPoint> |
||||||
|
#include <QTime> |
||||||
|
#include <QLabel> |
||||||
|
#include <QHBoxLayout> |
||||||
|
#include <QVBoxLayout> |
||||||
|
#include <QPushButton> |
||||||
|
|
||||||
|
#include "widget/croppinglabel.h" |
||||||
|
#include "widget/chatareawidget.h" |
||||||
|
#include "widget/tool/chattextedit.h" |
||||||
|
|
||||||
|
// Spacing in px inserted when the author of the last message changes
|
||||||
|
#define AUTHOR_CHANGE_SPACING 5 |
||||||
|
|
||||||
|
namespace Ui { |
||||||
|
class MainWindow; |
||||||
|
} |
||||||
|
|
||||||
|
class GenericChatForm : public QObject |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
GenericChatForm(QObject *parent = 0); |
||||||
|
virtual ~GenericChatForm(); |
||||||
|
|
||||||
|
virtual void setName(const QString &newName); |
||||||
|
virtual void show(Ui::MainWindow &ui); |
||||||
|
void addMessage(QString author, QString message, QDateTime datetime=QDateTime::currentDateTime()); |
||||||
|
|
||||||
|
signals: |
||||||
|
void sendMessage(int, QString); |
||||||
|
|
||||||
|
public slots: |
||||||
|
|
||||||
|
protected slots: |
||||||
|
void onChatContextMenuRequested(QPoint pos); |
||||||
|
void onSaveLogClicked(); |
||||||
|
void onEmoteButtonClicked(); |
||||||
|
void onEmoteInsertRequested(QString str); |
||||||
|
|
||||||
|
protected: |
||||||
|
CroppingLabel *nameLabel; |
||||||
|
QLabel *avatarLabel; |
||||||
|
QWidget *mainWidget, *headWidget; |
||||||
|
QPushButton *fileButton, *emoteButton, *callButton, *videoButton, *volButton, *micButton; |
||||||
|
QVBoxLayout *headTextLayout; |
||||||
|
ChatTextEdit *msgEdit; |
||||||
|
QPushButton *sendButton; |
||||||
|
QString previousName; |
||||||
|
ChatAreaWidget *chatWidget; |
||||||
|
int curRow; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // GENERICCHATFORM_H
|
@ -0,0 +1,120 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "chataction.h" |
||||||
|
#include "smileypack.h" |
||||||
|
#include <QStringList> |
||||||
|
#include <QBuffer> |
||||||
|
|
||||||
|
QString ChatAction::toHtmlChars(const QString &str) |
||||||
|
{ |
||||||
|
static QList<QPair<QString, QString>> replaceList = {{"&","&"}, {" "," "}, {">",">"}, {"<","<"}}; |
||||||
|
QString res = str; |
||||||
|
|
||||||
|
for (auto &it : replaceList) |
||||||
|
res = res.replace(it.first,it.second); |
||||||
|
|
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAction::QImage2base64(const QImage &img) |
||||||
|
{ |
||||||
|
QByteArray ba; |
||||||
|
QBuffer buffer(&ba); |
||||||
|
buffer.open(QIODevice::WriteOnly); |
||||||
|
img.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||||
|
return ba.toBase64(); |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAction::wrapName(const QString &name) |
||||||
|
{ |
||||||
|
if (isMe) |
||||||
|
return QString("<td><div class=name_me>" + name + "</div></td>\n"); |
||||||
|
else |
||||||
|
return QString("<td><div class=name>" + name + "</div></td>\n"); |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAction::wrapDate(const QString &date) |
||||||
|
{ |
||||||
|
QString res = "<td align=right><div class=date>" + date + "</div></td>\n"; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAction::wrapMessage(const QString &message) |
||||||
|
{ |
||||||
|
QString res = "<td width=100%><div class=message>" + message + "</div></td>\n"; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QString ChatAction::wrapWholeLine(const QString &line) |
||||||
|
{ |
||||||
|
QString res = "<tr>\n" + line + "</tr>\n"; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) : |
||||||
|
ChatAction(me) |
||||||
|
{ |
||||||
|
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message)); |
||||||
|
|
||||||
|
QStringList messageLines = message_.split("\n"); |
||||||
|
message_ = ""; |
||||||
|
for (QString& s : messageLines) |
||||||
|
{ |
||||||
|
if (QRegExp("^[ ]*>.*").exactMatch(s)) |
||||||
|
message_ += "<div class=quote>" + s.right(s.length()-4) + "</div><br>"; |
||||||
|
else |
||||||
|
message_ += s + "<br>"; |
||||||
|
} |
||||||
|
message_ = message_.left(message_.length()-4); |
||||||
|
|
||||||
|
content = wrapWholeLine(wrapName(author) + wrapMessage(message_) + wrapDate(date)); |
||||||
|
} |
||||||
|
|
||||||
|
QString MessageAction::getHtml() |
||||||
|
{ |
||||||
|
return content; |
||||||
|
} |
||||||
|
|
||||||
|
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me) : |
||||||
|
ChatAction(me), |
||||||
|
sender(author), |
||||||
|
timestamp(date) |
||||||
|
{ |
||||||
|
w = widget; |
||||||
|
} |
||||||
|
|
||||||
|
FileTransferAction::~FileTransferAction() |
||||||
|
{ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferAction::getHtml() |
||||||
|
{ |
||||||
|
QString widgetHtml; |
||||||
|
if (w != nullptr) |
||||||
|
widgetHtml = w->getHtmlImage(); |
||||||
|
else |
||||||
|
widgetHtml = "<div class=quote>EMPTY CONTENT</div>"; |
||||||
|
QString res = wrapWholeLine(wrapName(sender) + wrapMessage(widgetHtml) + wrapDate(timestamp));; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QString FileTransferAction::wrapMessage(const QString &message) |
||||||
|
{ |
||||||
|
QString res = "<td width=100%>" + message + "</td>\n"; |
||||||
|
return res; |
||||||
|
} |
@ -0,0 +1,67 @@ |
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||||
|
|
||||||
|
This program is libre software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
|
|
||||||
|
See the COPYING file for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef CHATACTION_H |
||||||
|
#define CHATACTION_H |
||||||
|
|
||||||
|
#include <QString> |
||||||
|
#include "filetransferinstance.h" |
||||||
|
|
||||||
|
class ChatAction |
||||||
|
{ |
||||||
|
public: |
||||||
|
ChatAction(const bool &me) : isMe(me) {;} |
||||||
|
virtual ~ChatAction(){;} |
||||||
|
virtual QString getHtml() = 0; |
||||||
|
|
||||||
|
protected: |
||||||
|
QString toHtmlChars(const QString &str); |
||||||
|
QString QImage2base64(const QImage &img); |
||||||
|
|
||||||
|
virtual QString wrapName(const QString &name); |
||||||
|
virtual QString wrapDate(const QString &date); |
||||||
|
virtual QString wrapMessage(const QString &message); |
||||||
|
virtual QString wrapWholeLine(const QString &line); |
||||||
|
|
||||||
|
private: |
||||||
|
bool isMe; |
||||||
|
}; |
||||||
|
|
||||||
|
class MessageAction : public ChatAction |
||||||
|
{ |
||||||
|
public: |
||||||
|
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me); |
||||||
|
virtual ~MessageAction(){;} |
||||||
|
virtual QString getHtml(); |
||||||
|
|
||||||
|
private: |
||||||
|
QString content; |
||||||
|
}; |
||||||
|
|
||||||
|
class FileTransferAction : public ChatAction |
||||||
|
{ |
||||||
|
public: |
||||||
|
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me); |
||||||
|
virtual ~FileTransferAction(); |
||||||
|
virtual QString getHtml(); |
||||||
|
virtual QString wrapMessage(const QString &message); |
||||||
|
|
||||||
|
private: |
||||||
|
FileTransferInstance *w; |
||||||
|
QString sender, timestamp; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // CHATACTION_H
|