diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 1a6f5acaa..56b3cf2c6 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -463,6 +463,7 @@ SOURCES += main.cpp \ util/rsversion.cpp \ util/printpreview.cpp \ util/log.cpp \ + util/misc.cpp \ gui/bwgraph/bwgraph.cpp \ gui/profile/ProfileView.cpp \ gui/profile/ProfileEdit.cpp \ diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index cf1d552f0..a89189fc4 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include "common/vmessagebox.h" #include "common/StatusDefs.h" diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 535bcb66b..058dfb1c7 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -294,51 +293,48 @@ void NetworkDialog::peerdetails() } /** Open a QFileDialog to browse for a pem/pqi file. */ -void NetworkDialog::loadcert() -{ - /* Create a new input dialog, which allows users to create files, too */ - QFileDialog dialog (this, tr("Select a pem/pqi File")); - //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); - //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); - dialog.setFileMode(QFileDialog::AnyFile); - dialog.setReadOnly(false); - - /* Prompt the user to select a file or create a new one */ - if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { - return; - } - QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); - - /* Check if the file exists */ - QFile torrcFile(filename); - if (!QFileInfo(filename).exists()) { - /* The given file does not exist. Should we create it? */ - int response = VMessageBox::question(this, - tr("File Not Found"), - tr("%1 does not exist. Would you like to create it?") - .arg(filename), - VMessageBox::Yes, VMessageBox::No); - - if (response == VMessageBox::No) { - /* Don't create it. Just bail. */ - return; - } - /* Attempt to create the specified file */ - if (!torrcFile.open(QIODevice::WriteOnly)) { - VMessageBox::warning(this, - tr("Failed to Create File"), - tr("Unable to create %1 [%2]").arg(filename) - .arg(torrcFile.errorString()), - VMessageBox::Ok); - return; - } - } - //ui.lineTorConfig->setText(filename); -} - - - -#include +//void NetworkDialog::loadcert() +//{ +// use misc::getOpenFileName +// /* Create a new input dialog, which allows users to create files, too */ +// QFileDialog dialog (this, tr("Select a pem/pqi File")); +// //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); +// //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); +// dialog.setFileMode(QFileDialog::AnyFile); +// dialog.setReadOnly(false); +// +// /* Prompt the user to select a file or create a new one */ +// if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { +// return; +// } +// QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); +// +// /* Check if the file exists */ +// QFile torrcFile(filename); +// if (!QFileInfo(filename).exists()) { +// /* The given file does not exist. Should we create it? */ +// int response = VMessageBox::question(this, +// tr("File Not Found"), +// tr("%1 does not exist. Would you like to create it?") +// .arg(filename), +// VMessageBox::Yes, VMessageBox::No); +// +// if (response == VMessageBox::No) { +// /* Don't create it. Just bail. */ +// return; +// } +// /* Attempt to create the specified file */ +// if (!torrcFile.open(QIODevice::WriteOnly)) { +// VMessageBox::warning(this, +// tr("Failed to Create File"), +// tr("Unable to create %1 [%2]").arg(filename) +// .arg(torrcFile.errorString()), +// VMessageBox::Ok); +// return; +// } +// } +// //ui.lineTorConfig->setText(filename); +//} void NetworkDialog::updateDisplay() { @@ -580,128 +576,131 @@ RsCertId getNeighRsCertId(QTreeWidgetItem *i) * All of these rely on the finding of the current Id. */ -std::string NetworkDialog::loadneighbour() -{ -#ifdef NET_DEBUG - std::cerr << "NetworkDialog::loadneighbour()" << std::endl; -#endif - QString fileName = QFileDialog::getOpenFileName(this, tr("Select Certificate"), "", - tr("Certificates (*.pqi *.pem)")); +//std::string NetworkDialog::loadneighbour() +//{ +//#ifdef NET_DEBUG +// std::cerr << "NetworkDialog::loadneighbour()" << std::endl; +//#endif +// use misc::getOpenFileName +// QString fileName = QFileDialog::getOpenFileName(this, tr("Select Certificate"), "", +// tr("Certificates (*.pqi *.pem)")); +// +// std::string file = fileName.toStdString(); +// std::string id; +// std::string gpg_id; +// if (file != "") +// { +// rsPeers->loadCertificateFromFile(file, id, gpg_id); +// } +// return id; +//} - std::string file = fileName.toStdString(); - std::string id; - std::string gpg_id; - if (file != "") - { - rsPeers->loadCertificateFromFile(file, id, gpg_id); - } - return id; -} +//void NetworkDialog::addneighbour() +//{ +//// QTreeWidgetItem *c = getCurrentNeighbour(); +//#ifdef NET_DEBUG +// std::cerr << "NetworkDialog::addneighbour()" << std::endl; +//#endif +// /* +// rsServer->NeighAddFriend(getNeighRsCertId(c)); +// */ +//} -void NetworkDialog::addneighbour() -{ -// QTreeWidgetItem *c = getCurrentNeighbour(); -#ifdef NET_DEBUG - std::cerr << "NetworkDialog::addneighbour()" << std::endl; -#endif - /* - rsServer->NeighAddFriend(getNeighRsCertId(c)); - */ -} - -void NetworkDialog::authneighbour() -{ -// QTreeWidgetItem *c = getCurrentNeighbour(); -#ifdef NET_DEBUG - std::cerr << "NetworkDialog::authneighbour()" << std::endl; -#endif - /* - RsAuthId code; - rsServer->NeighAuthFriend(getNeighRsCertId(c), code); - */ -} +//void NetworkDialog::authneighbour() +//{ +//// QTreeWidgetItem *c = getCurrentNeighbour(); +//#ifdef NET_DEBUG +// std::cerr << "NetworkDialog::authneighbour()" << std::endl; +//#endif +// /* +// RsAuthId code; +// rsServer->NeighAuthFriend(getNeighRsCertId(c), code); +// */ +//} /** Open a QFileDialog to browse for a pem/pqi file. */ void NetworkDialog::on_actionAddFriend_activated() { - /* Create a new input dialog, which allows users to create files, too */ - QFileDialog dialog (this, tr("Select a pem/pqi File")); - //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); - //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); - dialog.setFileMode(QFileDialog::AnyFile); - dialog.setReadOnly(false); - - /* Prompt the user to select a file or create a new one */ - if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { - return; - } - QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); - - /* Check if the file exists */ - QFile torrcFile(filename); - if (!QFileInfo(filename).exists()) { - /* The given file does not exist. Should we create it? */ - int response = VMessageBox::question(this, - tr("File Not Found"), - tr("%1 does not exist. Would you like to create it?") - .arg(filename), - VMessageBox::Yes, VMessageBox::No); - - if (response == VMessageBox::No) { - /* Don't create it. Just bail. */ - return; - } - /* Attempt to create the specified file */ - if (!torrcFile.open(QIODevice::WriteOnly)) { - VMessageBox::warning(this, - tr("Failed to Create File"), - tr("Unable to create %1 [%2]").arg(filename) - .arg(torrcFile.errorString()), - VMessageBox::Ok); - return; - } - } - //ui.lineTorConfig->setText(filename); +// /* Create a new input dialog, which allows users to create files, too */ +// use misc::getOpenFileName +// QFileDialog dialog (this, tr("Select a pem/pqi File")); +// //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); +// //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); +// dialog.setFileMode(QFileDialog::AnyFile); +// dialog.setReadOnly(false); +// +// /* Prompt the user to select a file or create a new one */ +// if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { +// return; +// } +// QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); +// +// /* Check if the file exists */ +// QFile torrcFile(filename); +// if (!QFileInfo(filename).exists()) { +// /* The given file does not exist. Should we create it? */ +// int response = VMessageBox::question(this, +// tr("File Not Found"), +// tr("%1 does not exist. Would you like to create it?") +// .arg(filename), +// VMessageBox::Yes, VMessageBox::No); +// +// if (response == VMessageBox::No) { +// /* Don't create it. Just bail. */ +// return; +// } +// /* Attempt to create the specified file */ +// if (!torrcFile.open(QIODevice::WriteOnly)) { +// VMessageBox::warning(this, +// tr("Failed to Create File"), +// tr("Unable to create %1 [%2]").arg(filename) +// .arg(torrcFile.errorString()), +// VMessageBox::Ok); +// return; +// } +// } +// //ui.lineTorConfig->setText(filename); } void NetworkDialog::on_actionExportKey_activated() { - qDebug() << " exportcert"; - - std::string cert = rsPeers->GetRetroshareInvite(); - if (cert.empty()) { - QMessageBox::information(this, tr("RetroShare"), - tr("Sorry, create certificate failed"), - QMessageBox::Ok, QMessageBox::Ok); - return; - } - - QString qdir = QFileDialog::getSaveFileName(this, - tr("Please choose a filename"), - QDir::homePath(), - tr("RetroShare Certificate (*.rsc );;All Files (*)")); - //Todo: move save to file to p3Peers::SaveCertificateToFile - - if (qdir.isEmpty() == false) { - QFile CertFile (qdir); - if (CertFile.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { - if (CertFile.write(QByteArray(cert.c_str())) > 0) { - QMessageBox::information(this, tr("RetroShare"), - tr("Certificate file successfully created"), - QMessageBox::Ok, QMessageBox::Ok); - } else { - QMessageBox::information(this, tr("RetroShare"), - tr("Sorry, certificate file creation failed"), - QMessageBox::Ok, QMessageBox::Ok); - } - CertFile.close(); - } else { - QMessageBox::information(this, tr("RetroShare"), - tr("Sorry, certificate file creation failed"), - QMessageBox::Ok, QMessageBox::Ok); - } - } +// qDebug() << " exportcert"; +// +// std::string cert = rsPeers->GetRetroshareInvite(); +// if (cert.empty()) { +// QMessageBox::information(this, tr("RetroShare"), +// tr("Sorry, create certificate failed"), +// QMessageBox::Ok, QMessageBox::Ok); +// return; +// } +// +// use misc::getSaveFileName +// QString qdir = QFileDialog::getSaveFileName(this, +// tr("Please choose a filename"), +// QDir::homePath(), +// tr("RetroShare Certificate (*.rsc );;All Files (*)")); +// //Todo: move save to file to p3Peers::SaveCertificateToFile +// +// if (qdir.isEmpty() == false) { +// QFile CertFile (qdir); +// if (CertFile.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { +// if (CertFile.write(QByteArray(cert.c_str())) > 0) { +// QMessageBox::information(this, tr("RetroShare"), +// tr("Certificate file successfully created"), +// QMessageBox::Ok, QMessageBox::Ok); +// } else { +// QMessageBox::information(this, tr("RetroShare"), +// tr("Sorry, certificate file creation failed"), +// QMessageBox::Ok, QMessageBox::Ok); +// } +// CertFile.close(); +// } else { +// QMessageBox::information(this, tr("RetroShare"), +// tr("Sorry, certificate file creation failed"), +// QMessageBox::Ok, QMessageBox::Ok); +// } +// } } void NetworkDialog::on_actionCreate_New_Profile_activated() diff --git a/retroshare-gui/src/gui/NetworkDialog.h b/retroshare-gui/src/gui/NetworkDialog.h index ed88c7343..91fb0611a 100644 --- a/retroshare-gui/src/gui/NetworkDialog.h +++ b/retroshare-gui/src/gui/NetworkDialog.h @@ -39,7 +39,7 @@ public: public slots: void insertConnect(); - std::string loadneighbour(); +// std::string loadneighbour(); /* void loadneighbour(); */ void updateNewDiscoveryInfo() ; @@ -55,10 +55,10 @@ private slots: //void unvalidGPGkeyWidgetCostumPopupMenu( QPoint point ); /** Called when user clicks "Load Cert" to choose location of a Cert file */ - void loadcert(); +// void loadcert(); - void authneighbour(); - void addneighbour(); +// void authneighbour(); +// void addneighbour(); void on_actionAddFriend_activated(); //void on_actionCopyKey_activated(); diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index aab93bfa0..2615e246c 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include "common/vmessagebox.h" #include "common/StatusDefs.h" #include "common/GroupDefs.h" @@ -64,6 +63,7 @@ #include "MainWindow.h" #include "NewsFeed.h" +#include "util/misc.h" #include #include @@ -1103,18 +1103,15 @@ void PeersDialog::exportfriend() } std::string id = getPeerRsCertId(c); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save Certificate"), "", - tr("Certificates (*.pqi)")); - std::string file = fileName.toStdString(); - if (file != "") + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_CERT, tr("Save Certificate"), tr("Certificates (*.pqi)"), fileName)) { #ifdef PEERS_DEBUG std::cerr << "PeersDialog::exportfriend() Saving to: " << file << std::endl; #endif if (rsPeers) { - rsPeers->saveCertificateToFile(id, file); + rsPeers->saveCertificateToFile(id, fileName.toUtf8().constData()); } } @@ -1727,8 +1724,8 @@ void PeersDialog::updateAvatar() void PeersDialog::getAvatar() { - QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg *.tiff *.gif)"); - if(!fileName.isEmpty()) + QString fileName; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName)) { QPixmap picture; picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation); @@ -1794,14 +1791,10 @@ void PeersDialog::statusmessage() void PeersDialog::addExtraFile() { - // select a file - QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, - QFileDialog::DontResolveSymlinks); - std::string filePath = qfile.toStdString(); - if (filePath != "") - { - PeersDialog::addAttachment(filePath); - } + QString file; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", file)) { + addAttachment(file.toUtf8().constData()); + } } void PeersDialog::addAttachment(std::string filePath) { @@ -1950,12 +1943,13 @@ bool PeersDialog::fileSave() bool PeersDialog::fileSaveAs() { - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("Text File (*.txt );;All Files (*)")); - if (fn.isEmpty()) - return false; - setCurrentFileName(fn); - return fileSave(); + QString fn; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_HISTORY, tr("Save as..."), tr("Text File (*.txt );;All Files (*)"), fn)) { + setCurrentFileName(fn); + return fileSave(); + } + + return false; } void PeersDialog::setCurrentFileName(const QString &fileName) diff --git a/retroshare-gui/src/gui/PluginManagerWidget.cpp b/retroshare-gui/src/gui/PluginManagerWidget.cpp index 7e7b6274f..b017bf700 100644 --- a/retroshare-gui/src/gui/PluginManagerWidget.cpp +++ b/retroshare-gui/src/gui/PluginManagerWidget.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include diff --git a/retroshare-gui/src/gui/RSHumanReadableDelegate.h b/retroshare-gui/src/gui/RSHumanReadableDelegate.h index 944f7980f..08165b4a1 100644 --- a/retroshare-gui/src/gui/RSHumanReadableDelegate.h +++ b/retroshare-gui/src/gui/RSHumanReadableDelegate.h @@ -38,6 +38,7 @@ */ #include +#include #include class RSHumanReadableDelegate: public QAbstractItemDelegate diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index c926a39fc..57b919580 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -20,6 +20,7 @@ ****************************************************************/ #include +#include #include "SearchDialog.h" #include "RetroShareLink.h" diff --git a/retroshare-gui/src/gui/channels/CreateChannel.cpp b/retroshare-gui/src/gui/channels/CreateChannel.cpp index 4ddca74c1..f7acdfec1 100644 --- a/retroshare-gui/src/gui/channels/CreateChannel.cpp +++ b/retroshare-gui/src/gui/channels/CreateChannel.cpp @@ -21,7 +21,6 @@ #include #include -#include #include @@ -244,8 +243,8 @@ void CreateChannel::cancelChannel() void CreateChannel::addChannelLogo() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), QDir::homePath(), tr("Pictures (*.png *.xpm *.jpg)")); - if(!fileName.isEmpty()) + QString fileName; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName)) { picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio,Qt::SmoothTransformation); diff --git a/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp b/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp index 7879d3f61..79e73caed 100644 --- a/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp +++ b/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -289,14 +288,15 @@ void CreateChannelMsg::addAttachment(const std::string &hash, const std::string void CreateChannelMsg::addExtraFile() { - /* add a SubFileItem to the attachment section */ - std::cerr << "CreateChannelMsg::addExtraFile() opening file dialog"; - std::cerr << std::endl; + /* add a SubFileItem to the attachment section */ + std::cerr << "CreateChannelMsg::addExtraFile() opening file dialog"; + std::cerr << std::endl; - // select a file - QStringList files = QFileDialog::getOpenFileNames(this, tr("Add Extra File"), "", "", 0, QFileDialog::DontResolveSymlinks); - for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { - addAttachment((*fileIt).toUtf8().constData()); + QStringList files; + if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) { + for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { + addAttachment((*fileIt).toUtf8().constData()); + } } } @@ -563,8 +563,8 @@ void CreateChannelMsg::sendMessage(std::wstring subject, std::wstring msg, std:: void CreateChannelMsg::addThumbnail() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), QDir::homePath(), tr("Pictures (*.png *.xpm *.jpg)")); - if(!fileName.isEmpty()) + QString fileName; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName)) { picture = QPixmap(fileName).scaled(156,107, Qt::IgnoreAspectRatio,Qt::SmoothTransformation); diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 22e4f4af7..afd621843 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include "PopupChatDialog.h" #include "PopupChatWindow.h" #include "gui/RetroShareLink.h" +#include "util/misc.h" #include "rshare.h" #include @@ -889,26 +889,19 @@ void PopupChatDialog::updateAvatar() void PopupChatDialog::addExtraFile() { - // select a file - QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, - QFileDialog::DontResolveSymlinks); - std::string filePath = qfile.toStdString(); - if (filePath != "") - { - addAttachment(filePath,0); - } + QString file; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", file)) { + addAttachment(file.toUtf8().constData(), 0); + } } void PopupChatDialog::addExtraPicture() { - // select a picture file - QString qfile = QFileDialog::getOpenFileName(this, "Load Picture File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)",0, - QFileDialog::DontResolveSymlinks); - std::string filePath=qfile.toStdString(); - if(filePath!="") - { - PopupChatDialog::addAttachment(filePath,1); //picture - } + // select a picture file + QString file; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg)", file)) { + addAttachment(file.toUtf8().constData(), 1); + } } void PopupChatDialog::addAttachment(std::string filePath,int flag) @@ -1115,12 +1108,13 @@ bool PopupChatDialog::fileSave() bool PopupChatDialog::fileSaveAs() { - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("Text File (*.txt );;All Files (*)")); - if (fn.isEmpty()) - return false; - setCurrentFileName(fn); - return fileSave(); + QString fn; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_HISTORY, tr("Save as..."), tr("Text File (*.txt );;All Files (*)"), fn)) { + setCurrentFileName(fn); + return fileSave(); + } + + return false; } void PopupChatDialog::setCurrentFileName(const QString &fileName) diff --git a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp index 347968ba9..c7ba08f0d 100644 --- a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp @@ -21,13 +21,13 @@ ****************************************************************/ #include -#include #include "PopupChatWindow.h" #include "PopupChatDialog.h" #include "gui/settings/rsharesettings.h" #include "gui/settings/RsharePeerSettings.h" #include "gui/common/StatusDefs.h" +#include"util/misc.h" #include #include @@ -262,9 +262,9 @@ void PopupChatWindow::calculateTitle(PopupChatDialog *dialog) void PopupChatWindow::getAvatar() { - QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)"); - - if(!fileName.isEmpty()) { + QString fileName; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName)) + { QPixmap picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation); std::cerr << "Sending avatar image down the pipe" << std::endl; diff --git a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp index f4886635d..a3ed6cef8 100644 --- a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp +++ b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -195,14 +194,12 @@ void CreateForumMsg::addSmileys() void CreateForumMsg::addFile() { - // select a file - QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, - QFileDialog::DontResolveSymlinks); - std::string filePath = qfile.toStdString(); - if (filePath != "") - { - CreateForumMsg::addAttachment(filePath); - } + QStringList files; + if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) { + for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { + addAttachment((*fileIt).toUtf8().constData()); + } + } } void CreateForumMsg::addAttachment(std::string filePath) { @@ -236,21 +233,18 @@ void CreateForumMsg::fileHashingFinished(AttachFileItem* file) { return; } - //convert fileSize from uint_64 to string for html link - char fileSizeChar [100]; - sprintf(fileSizeChar, "%llu", (unsigned long long int)file->FileSize()); - std::string fileSize = *(&fileSizeChar); + RetroShareLink link(QString::fromUtf8(file->FileName().c_str()), file->FileSize(), QString::fromStdString(file->FileHash())); + if (link.valid()) { + QString mesgString = link.toHtmlSize() + "
"; - std::string mesgString = "" - + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "" + "
"; #ifdef CHAT_DEBUG - std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString << std::endl; + std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString.toStdString() << std::endl; #endif - ui.forumMessage->textCursor().insertHtml(QString::fromStdString(mesgString)); - - ui.forumMessage->setFocus( Qt::OtherFocusReason ); + ui.forumMessage->textCursor().insertHtml(mesgString); + ui.forumMessage->setFocus( Qt::OtherFocusReason ); + } } void CreateForumMsg::dropEvent(QDropEvent *event) diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 522555b85..cf07a4d95 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -25,12 +25,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include @@ -1894,10 +1894,10 @@ void MessageComposer::fileNew() void MessageComposer::fileOpen() { - QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."), - QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); - if (!fn.isEmpty()) + QString fn; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_MESSAGES, tr("Open File..."), tr("HTML-Files (*.htm *.html);;All Files (*)"), fn)) { load(fn); + } } bool MessageComposer::fileSave() @@ -1917,12 +1917,13 @@ bool MessageComposer::fileSave() bool MessageComposer::fileSaveAs() { - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); - if (fn.isEmpty()) - return false; - setCurrentFileName(fn); - return fileSave(); + QString fn; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_MESSAGES, tr("Save as..."), tr("HTML-Files (*.htm *.html);;All Files (*)"), fn)) { + setCurrentFileName(fn); + return fileSave(); + } + + return false; } void MessageComposer::saveasDraft() @@ -1949,9 +1950,8 @@ void MessageComposer::filePrint() void MessageComposer::filePrintPdf() { #ifndef QT_NO_PRINTER - QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", - QString(), "*.pdf"); - if (!fileName.isEmpty()) { + QString fileName; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_MESSAGES, tr("Export PDF"), "*.pdf", fileName)) { if (QFileInfo(fileName).suffix().isEmpty()) fileName.append(".pdf"); QPrinter printer(QPrinter::HighResolution); @@ -2024,19 +2024,15 @@ void MessageComposer::on_contactsdockWidget_visibilityChanged(bool visible) void MessageComposer::addImage() { - QString fileimg = QFileDialog::getOpenFileName( this, tr( "Choose Image" ), - QString(Settings->valueFromGroup("MessageComposer", "LastDir").toString()) ,tr("Image Files supported (*.png *.jpeg *.jpg *.gif)")); + QString fileimg; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Choose Image"), tr("Image Files supported (*.png *.jpeg *.jpg *.gif)"), fileimg)) { + QImage base(fileimg); - if ( fileimg.isEmpty() ) { - return; + QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/"; + Settings->setValueToGroup("MessageComposer", "LastDir", pathimage); + + Create_New_Image_Tag(fileimg); } - - QImage base(fileimg); - - QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/"; - Settings->setValueToGroup("MessageComposer", "LastDir", pathimage); - - Create_New_Image_Tag(fileimg); } void MessageComposer::Create_New_Image_Tag( const QString urlremoteorlocal ) @@ -2139,9 +2135,11 @@ void MessageComposer::addPostSplitter() void MessageComposer::attachFile() { // select a file - QStringList files = QFileDialog::getOpenFileNames(this, tr("Add Extra File"), "", "", 0, QFileDialog::DontResolveSymlinks); - for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { - MessageComposer::addAttachment((*fileIt).toUtf8().constData()); + QStringList files; + if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) { + for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { + addAttachment((*fileIt).toUtf8().constData()); + } } } diff --git a/retroshare-gui/src/gui/settings/CryptoPage.cpp b/retroshare-gui/src/gui/settings/CryptoPage.cpp index 5a89838db..9340f8187 100755 --- a/retroshare-gui/src/gui/settings/CryptoPage.cpp +++ b/retroshare-gui/src/gui/settings/CryptoPage.cpp @@ -21,11 +21,12 @@ #include #include -#include +#include #include #include #include "CryptoPage.h" +#include "util/misc.h" #include //for rsPeers variable @@ -115,12 +116,12 @@ bool CryptoPage::fileSave() bool CryptoPage::fileSaveAs() { - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("RetroShare Certificate (*.rsc );;All Files (*)")); - if (fn.isEmpty()) - return false; - setCurrentFileName(fn); - return fileSave(); + QString fn; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_CERT, tr("Save as..."), tr("RetroShare Certificate (*.rsc );;All Files (*)"), fn)) { + setCurrentFileName(fn); + return fileSave(); + } + return false; } void CryptoPage::setCurrentFileName(const QString &fileName) diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index ccef1392b..0d10936c8 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -173,6 +173,45 @@ void RshareSettings::setSheetName(QString sheet) setValue(SETTING_SHEETNAME, sheet); } +static QString getKeyForLastDir(RshareSettings::enumLastDir type) +{ + switch (type) { + case RshareSettings::LASTDIR_EXTRAFILE: + return "ExtraFile"; + case RshareSettings::LASTDIR_CERT: + return "Certificate"; + case RshareSettings::LASTDIR_HISTORY: + return "History"; + case RshareSettings::LASTDIR_IMAGES: + return "Images"; + case RshareSettings::LASTDIR_MESSAGES: + return "Messages"; + case RshareSettings::LASTDIR_BLOGS: + return "Messages"; + } + return ""; +} + +QString RshareSettings::getLastDir(enumLastDir type) +{ + QString key = getKeyForLastDir(type); + if (key.isEmpty()) { + return ""; + } + + return valueFromGroup("LastDir", key).toString(); +} + +void RshareSettings::setLastDir(enumLastDir type, const QString &lastDir) +{ + QString key = getKeyForLastDir(type); + if (key.isEmpty()) { + return; + } + + setValueToGroup("LastDir", key, lastDir); +} + /** Returns the bandwidth line filter. */ uint RshareSettings::getBWGraphFilter() { diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index 49af523db..1c7618655 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -55,7 +55,17 @@ class QMainWindow; */ class RshareSettings : public RSettings { - +public: + enum enumLastDir + { + LASTDIR_EXTRAFILE, + LASTDIR_CERT, + LASTDIR_HISTORY, + LASTDIR_IMAGES, + LASTDIR_MESSAGES, + LASTDIR_BLOGS + }; + public: /* create settings object */ static void Create (); @@ -92,6 +102,9 @@ public: /** Set the destination log file. */ void setLogFile(QString file); + QString getLastDir(enumLastDir type); + void setLastDir(enumLastDir type, const QString &lastDir); + /* Get the bandwidth graph line filter. */ uint getBWGraphFilter(); /** Set the bandwidth graph line filter. */ diff --git a/retroshare-gui/src/gui/unfinished/blogs/CreateBlog.cpp b/retroshare-gui/src/gui/unfinished/blogs/CreateBlog.cpp index da72637a4..3798041af 100644 --- a/retroshare-gui/src/gui/unfinished/blogs/CreateBlog.cpp +++ b/retroshare-gui/src/gui/unfinished/blogs/CreateBlog.cpp @@ -20,10 +20,10 @@ ****************************************************************/ #include -#include #include #include "CreateBlog.h" +#include "util/misc.h" #include @@ -143,8 +143,8 @@ void CreateBlog::createBlog() void CreateBlog::addBlogLogo(){ - QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)"); - if(!fileName.isEmpty()) + QString fileName; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName)) { picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio,Qt::SmoothTransformation); diff --git a/retroshare-gui/src/gui/unfinished/blogs/CreateBlogMsg.cpp b/retroshare-gui/src/gui/unfinished/blogs/CreateBlogMsg.cpp index ee65c73c2..3a1ff2959 100644 --- a/retroshare-gui/src/gui/unfinished/blogs/CreateBlogMsg.cpp +++ b/retroshare-gui/src/gui/unfinished/blogs/CreateBlogMsg.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -35,6 +35,7 @@ #include "CreateBlogMsg.h" #include "gui/msgs/textformat.h" +#include "util/misc.h" #include @@ -803,9 +804,8 @@ void CreateBlogMsg::fileNew() void CreateBlogMsg::fileOpen() { - QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."), - QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); - if (!fn.isEmpty()) + QString fn; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_BLOGS, tr("Open File..."), tr("HTML-Files (*.htm *.html);;All Files (*)"), fn)) load(fn); } @@ -823,14 +823,15 @@ bool CreateBlogMsg::fileSave() bool CreateBlogMsg::fileSaveAs() { - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)")); - if (fn.isEmpty()) - return false; - if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) ) - fn += ".odt"; // default - setCurrentFileName(fn); - return fileSave(); + QString fn; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_BLOGS, tr("Save as..."), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)"), fn)) { + if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) ) + fn += ".odt"; // default + setCurrentFileName(fn); + return fileSave(); + } + + return false; } void CreateBlogMsg::filePrint() @@ -872,9 +873,8 @@ void CreateBlogMsg::filePrintPdf() { #ifndef QT_NO_PRINTER //! [0] - QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", - QString(), "*.pdf"); - if (!fileName.isEmpty()) { + QString fileName; + if (misc::getSaveFileName(this, RshareSettings::LASTDIR_MESSAGES, tr("Export PDF"), "*.pdf", fileName)) { if (QFileInfo(fileName).suffix().isEmpty()) fileName.append(".pdf"); QPrinter printer(QPrinter::HighResolution); @@ -901,22 +901,14 @@ void CreateBlogMsg::setCurrentFileName(const QString &fileName) setWindowModified(false); } -void CreateBlogMsg::addImage() +void CreateBlogMsg::addImage() { - - QString fileimg = QFileDialog::getOpenFileName( this, tr( "Choose Image" ), - QString(setter.value("LastDir").toString()) ,tr("Image Files supported (*.png *.jpeg *.jpg *.gif)")); + QString fileimg; + if (misc::getOpenFileName(this, RshareSettings::LASTDIR_MESSAGES, tr("Choose Image"), tr("Image Files supported (*.png *.jpeg *.jpg *.gif)"), fileimg)) { + QImage base(fileimg); - if ( fileimg.isEmpty() ) { - return; + Create_New_Image_Tag(fileimg); } - - QImage base(fileimg); - - QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/"; - setter.setValue("LastDir",pathimage); - - Create_New_Image_Tag(fileimg); } void CreateBlogMsg::Create_New_Image_Tag( const QString urlremoteorlocal ) diff --git a/retroshare-gui/src/lang/retroshare_de.qm b/retroshare-gui/src/lang/retroshare_de.qm index 57abe5e7a..bc0f523d1 100644 Binary files a/retroshare-gui/src/lang/retroshare_de.qm and b/retroshare-gui/src/lang/retroshare_de.qm differ diff --git a/retroshare-gui/src/lang/retroshare_de.ts b/retroshare-gui/src/lang/retroshare_de.ts index ab40f8b08..5b1bfa257 100644 --- a/retroshare-gui/src/lang/retroshare_de.ts +++ b/retroshare-gui/src/lang/retroshare_de.ts @@ -1742,6 +1742,16 @@ p, li { white-space: pre-wrap; } Please add a Name Bitte Name hinzufügen + + + Load File + Lade Datei + + + + Pictures (*.png *.xpm *.jpg) + Bilder (*.png *.xpm *.jpg) + Authemticated Messages @@ -1876,7 +1886,7 @@ p, li { white-space: pre-wrap; } Rückgängig - + RetroShare @@ -2036,12 +2046,12 @@ Do you want to save your changes? Möchten Sie die Änderungen speichern? - + Open File... Datei öffnen... - + HTML-Files (*.htm *.html);;All Files (*) HTML-Dateien (*.htm *.html);;Alle Dateien (*) @@ -2051,22 +2061,27 @@ Möchten Sie die Änderungen speichern? Speichern unter... - + ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*) - + Print Document Dokument drucken - + + Export PDF + PDF exportieren + + + Choose Image Bild wählen - + Image Files supported (*.png *.jpeg *.jpg *.gif) Unterstützte Bilddateien (*.png *.jpeg *.jpg *.gif) @@ -2174,7 +2189,7 @@ Möchten Sie die Änderungen speichern? Erstellen - + RetroShare @@ -2184,7 +2199,7 @@ Möchten Sie die Änderungen speichern? Bitte einen Name hinzufügen - + Load File Lade Datei @@ -2285,12 +2300,12 @@ p, li { white-space: pre-wrap; } Drag'n'Drop Dateien aus den Suchergebnissen - + Add Extra File Zusätzlich eine Datei hinzufügen - + RetroShare @@ -2306,7 +2321,7 @@ p, li { white-space: pre-wrap; } Bitte Subjekt nicht vergessen - + Load File Lade Datei @@ -2436,7 +2451,7 @@ p, li { white-space: pre-wrap; } - + Paste RetroShare Link RetroShare Link einfügen @@ -2481,7 +2496,7 @@ p, li { white-space: pre-wrap; } Du kannst Dateien mit Drag'n'Drop anhängen - + Drop file error. Dateifehler bei Drag'n'Drop. @@ -2542,7 +2557,7 @@ p, li { white-space: pre-wrap; } CryptoPage - + RetroShare @@ -2552,12 +2567,12 @@ p, li { white-space: pre-wrap; } Dein öffentlicher Schlüssel ist in die Zwischenablage kopiert worden - + Save as... Speichern unter... - + RetroShare Certificate (*.rsc );;All Files (*) @@ -5827,18 +5842,18 @@ Möchtest Du die Nachricht in den Entwürfen speichern? &Format - + Open File... Datei öffnen... - + HTML-Files (*.htm *.html);;All Files (*) HTML-Dateien (*.htm *.html);;Alle Dateien (*) - + Save as... Speichern unter... @@ -5848,29 +5863,34 @@ Möchtest Du die Nachricht in den Entwürfen speichern? Dokument drucken - + + Export PDF + PDF exportieren + + + Message has not been Sent. Do you want to save message ? Nachricht noch nicht versandt. Willst Du die Nachricht speichern ? - + Choose Image Bild wählen - + Image Files supported (*.png *.jpeg *.jpg *.gif) Unterstützte Bilddateien (*.png *.jpeg *.jpg *.gif) - + Add Extra File Zusätzliche Datei hinzufügen - + Drop file error. Dateifehler bei Drag'n'Drop. @@ -5886,7 +5906,7 @@ Willst Du die Nachricht speichern ? Datei nicht gefunden oder Dateiname nicht akzeptiert. - + Friend Recommendation(s) Freundempfehlung(en) @@ -6372,7 +6392,7 @@ p, li { white-space: pre-wrap; } MessengerWindow - + Expand all Alle erweitern @@ -6587,37 +6607,27 @@ p, li { white-space: pre-wrap; } NetworkDialog - - Select a pem/pqi File - Wählen einer PEM- oder PQI-Datei + Wählen einer PEM- oder PQI-Datei - - File Not Found - Datei nicht gefunden + Datei nicht gefunden - - %1 does not exist. Would you like to create it? - %1 ist nicht vorhanden. Möchten Sie es jetzt erstellen? + %1 ist nicht vorhanden. Möchten Sie es jetzt erstellen? - - Failed to Create File - Es ist nicht gelungen, die Datei zu erstellen + Es ist nicht gelungen, die Datei zu erstellen - - Unable to create %1 [%2] - Kann %1 [%2] nicht erstellen + Kann %1 [%2] nicht erstellen - + Personal signature @@ -6654,14 +6664,12 @@ Right-click and select 'make friend' to be able to connect. Rechtsklick und als Freund hinzufügen um zu verbinden. - Select Certificate - Zertifikat auswählen + Zertifikat auswählen - Certificates (*.pqi *.pem) - Zertifikate (*.pqi *.pem) + Zertifikate (*.pqi *.pem) @@ -6772,7 +6780,7 @@ p, li { white-space: pre-wrap; } Leeren - + Deny friend Blockiere Freund @@ -6797,12 +6805,12 @@ p, li { white-space: pre-wrap; } Nachbar-Details... - + Unknown Unbekannt - + Authentication matrix Authentifizierungsmatrix @@ -6812,28 +6820,17 @@ p, li { white-space: pre-wrap; } Netzwerk Ansicht - + yourself selbst - - - - - RetroShare - - - - Certificate file successfully created - Zertifikat-Datei erfolgreich erstellt + Zertifikat-Datei erfolgreich erstellt - - Sorry, certificate file creation failed - Zertifikat-Datei konnte nicht erstellt werden + Zertifikat-Datei konnte nicht erstellt werden @@ -6889,19 +6886,16 @@ p, li { white-space: pre-wrap; } Peer ID - Sorry, create certificate failed - Zertifikat-Datei konnte nicht erstellt werden + Zertifikat-Datei konnte nicht erstellt werden - Please choose a filename - Bitte wählen sie einen Dateinamen + Bitte wählen sie einen Dateinamen - RetroShare Certificate (*.rsc );;All Files (*) - RetroShare Zertifikat (*.rsc );;Alle Dateien (*) + RetroShare Zertifikat (*.rsc );;Alle Dateien (*) @@ -7315,12 +7309,12 @@ p, li { white-space: pre-wrap; } Chat - + Save Certificate Zertifikat speichern - + Certificates (*.pqi) Zertifikate (*.pqi) @@ -7435,18 +7429,28 @@ p, li { white-space: pre-wrap; } Verfügbar - + New group chat Neuer Gruppenchat - + + Load File + Lade Datei + + + + Pictures (*.png *.xpm *.jpg *.tiff *.gif) + Bilder (*.png *.xpm *.jpg *.tiff *.gif) + + + Add Extra File Zusätzliche Datei hinzufügen - + Drop file error. Dateifehler bei Drag'n'Drop. @@ -7554,7 +7558,7 @@ p, li { white-space: pre-wrap; } - + Add Friend Freund hinzufügen @@ -7609,12 +7613,12 @@ p, li { white-space: pre-wrap; } - + RetroShare - + Message Group Gruppe anschreiben @@ -7629,17 +7633,17 @@ p, li { white-space: pre-wrap; } Gruppe entfernen - + Do you want to remove this Friend? Willst du diesen Freund entfernen? - + Save as... Speichern unter... - + Text File (*.txt );;All Files (*) Text Datei (*.txt );;Alle Dateien (*) @@ -7667,12 +7671,12 @@ p, li { white-space: pre-wrap; } Status Spalte ausblenden - + Friends Storm Aktivitäten - + is typing... tippt... @@ -7692,7 +7696,7 @@ p, li { white-space: pre-wrap; } Freunde - + Paste Friend Link RetroShare Link einfügen @@ -7969,7 +7973,7 @@ p, li { white-space: pre-wrap; } PluginFrame - + Remove Entfernen @@ -8005,12 +8009,17 @@ p, li { white-space: pre-wrap; } Avatar zeigen - + + Load Picture File + Lade Bilddatei + + + File not found or file name not accepted. Datei nicht gefunden oder Dateiname nicht akzeptiert. - + Messages you send will be delivered after Friend is again Online Nachrichten, die Du versendest gehen bei diesem Freund erst wieder ein wenn er Online ist @@ -8078,12 +8087,12 @@ p, li { white-space: pre-wrap; } Durchgestrichen - + Add Extra File Zusätzlich eine Datei hinzufügen - + Drop file error. Dateifehler bei Drag'n'Drop. @@ -8105,17 +8114,17 @@ p, li { white-space: pre-wrap; } Chat Verlauf speichern - + Save as... Speichern unter... - + Text File (*.txt );;All Files (*) Text Datei (*.txt );;Alle Dateien (*) - + Your Friend is offline Do you want to send them a Message instead Dein Freund ist Offline willst du ihm stattdessen eine Nachricht senden @@ -8126,7 +8135,7 @@ Do you want to send them a Message instead Bild anhängen - + is Idle and may not reply antwortet möglicherweise nicht, da der Status auf "Untätig" gesetzt wurde @@ -8146,7 +8155,7 @@ Do you want to send them a Message instead ist Offline. - + Paste RetroShare Link RetroShare Link einfügen @@ -8195,6 +8204,16 @@ Do you want to send them a Message instead RetroShare RetroShare + + + Load File + Lade Datei + + + + Pictures (*.png *.xpm *.jpg *.tiff *.gif) + Bilder (*.png *.xpm *.jpg *.tiff *.gif) + PrintPreview @@ -8336,7 +8355,7 @@ Do you want to send them a Message instead ProfileView - + Clear Photo Photo entfernen @@ -8743,17 +8762,17 @@ p, li { white-space: pre-wrap; } Deny friend - Blockiere Freund + Blockiere Freund Make friend - Freund hinzufügen + Freund hinzufügen Peer details - Nachbar Details + Nachbar Details @@ -9281,7 +9300,7 @@ p, li { white-space: pre-wrap; } - + Download Herunterladen @@ -10694,7 +10713,7 @@ p, li { white-space: pre-wrap; } - + Play File Datei abspielen @@ -11473,7 +11492,7 @@ p, li { white-space: pre-wrap; } misc - + Unknown Unknown (size) Unbekannt @@ -11509,7 +11528,7 @@ p, li { white-space: pre-wrap; } - + Unknown Unbekannt diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp new file mode 100644 index 000000000..cebdd56cb --- /dev/null +++ b/retroshare-gui/src/util/misc.cpp @@ -0,0 +1,286 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2008, defnax + * Copyright (C) 2006 Christophe Dumez + * + * This program is free 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 2 + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + *************************************************************************/ + +#include +#include +#include + +#include "misc.h" + +// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB) +// use Binary prefix standards from IEC 60027-2 +// see http://en.wikipedia.org/wiki/Kilobyte +// value must be given in bytes +QString misc::friendlyUnit(float val) +{ + if(val < 0) { + return tr("Unknown", "Unknown (size)"); + } + const QString units[4] = {tr(" B", "bytes"), tr(" KiB", "kibibytes (1024 bytes)"), tr(" MiB", "mebibytes (1024 kibibytes)"), tr(" GiB", "gibibytes (1024 mibibytes)")}; + for(unsigned int i=0; i<5; ++i) { + if (val < 1024.) { + return QString(QByteArray::number(val, 'f', 1)) + units[i]; + } + val /= 1024.; + } + return QString(QByteArray::number(val, 'f', 1)) + tr(" TiB", "tebibytes (1024 gibibytes)"); +} + +bool misc::isPreviewable(QString extension) +{ + extension = extension.toUpper(); + if(extension == "AVI") return true; + if(extension == "MP3") return true; + if(extension == "OGG") return true; + if(extension == "OGM") return true; + if(extension == "WMV") return true; + if(extension == "WMA") return true; + if(extension == "MPEG") return true; + if(extension == "MPG") return true; + if(extension == "ASF") return true; + if(extension == "QT") return true; + if(extension == "RM") return true; + if(extension == "RMVB") return true; + if(extension == "RMV") return true; + if(extension == "SWF") return true; + if(extension == "FLV") return true; + if(extension == "WAV") return true; + if(extension == "MOV") return true; + if(extension == "VOB") return true; + if(extension == "MID") return true; + if(extension == "AC3") return true; + if(extension == "MP4") return true; + if(extension == "MP2") return true; + if(extension == "AVI") return true; + if(extension == "FLAC") return true; + if(extension == "AU") return true; + if(extension == "MPE") return true; + if(extension == "MOV") return true; + if(extension == "MKV") return true; + if(extension == "AIF") return true; + if(extension == "AIFF") return true; + if(extension == "AIFC") return true; + if(extension == "RA") return true; + if(extension == "RAM") return true; + if(extension == "M4P") return true; + if(extension == "M4A") return true; + if(extension == "3GP") return true; + if(extension == "AAC") return true; + if(extension == "SWA") return true; + if(extension == "MPC") return true; + if(extension == "MPP") return true; + return false; +} + +// return qBittorrent config path +QString misc::qBittorrentPath() +{ + QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator(); + // Create dir if it does not exist + if(!QFile::exists(qBtPath)){ + QDir dir(qBtPath); + dir.mkpath(qBtPath); + } + return qBtPath; +} + +QString misc::findFileInDir(QString dir_path, QString fileName) +{ + QDir dir(dir_path); + if(dir.exists(fileName)) { + return dir.filePath(fileName); + } + QStringList subDirs = dir.entryList(QDir::Dirs); + QString subdir_name; + foreach(subdir_name, subDirs) { + QString result = findFileInDir(dir.path()+QDir::separator()+subdir_name, fileName); + if(!result.isNull()) { + return result; + } + } + return QString(); +} + +// Can't use template class for QString because >,< use unicode code for sorting +// which is not what a human would expect when sorting strings. +void misc::insertSortString(QList > &list, QPair value, Qt::SortOrder sortOrder) +{ + int i = 0; + if(sortOrder == Qt::AscendingOrder) { + while(i < list.size() and QString::localeAwareCompare(value.second, list.at(i).second) > 0) { + ++i; + } + }else{ + while(i < list.size() and QString::localeAwareCompare(value.second, list.at(i).second) < 0) { + ++i; + } + } + list.insert(i, value); +} + +float misc::getPluginVersion(QString filePath) +{ + QFile plugin(filePath); + if(!plugin.exists()){ + qDebug("%s plugin does not exist, returning 0.0", filePath.toUtf8().data()); + return 0.0; + } + if(!plugin.open(QIODevice::ReadOnly | QIODevice::Text)){ + return 0.0; + } + float version = 0.0; + while (!plugin.atEnd()){ + QByteArray line = plugin.readLine(); + if(line.startsWith("#VERSION: ")){ + line = line.split(' ').last(); + line.replace("\n", ""); + version = line.toFloat(); + qDebug("plugin %s version: %.2f", filePath.toUtf8().data(), version); + break; + } + } + return version; +} + +// Take a number of seconds and return an user-friendly +// time duration like "1d 2h 10m". +QString misc::userFriendlyDuration(qlonglong seconds) +{ + if(seconds < 0) { + return tr("Unknown"); + } + if(seconds < 60) { + return tr("< 1m", "< 1 minute"); + } + int minutes = seconds / 60; + if(minutes < 60) { + return tr("%1 minutes","e.g: 10minutes").arg(QString::QString::fromUtf8(misc::toString(minutes).c_str())); + } + int hours = minutes / 60; + minutes = minutes - hours*60; + if(hours < 24) { + return tr("%1h %2m", "e.g: 3hours 5minutes").arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str())); + } + int days = hours / 24; + hours = hours - days * 24; + if(days < 365) { + return tr("%1d %2h", "e.g: 2days 10hours").arg(QString::fromUtf8(misc::toString(days).c_str())).arg(QString::fromUtf8(misc::toString(hours).c_str())); + } + int years = days / 365; + days = days - years * 365; + return tr("%1y %2d", "e.g: 2 years 2days ").arg(QString::fromUtf8(misc::toString(years).c_str())).arg(QString::fromUtf8(misc::toString(days).c_str())); +} + +QString misc::userFriendlyUnit(double count, unsigned int decimal, double factor) +{ + if (count <= 0.0) { + return "0"; + } + + QString output; + + int i; + for (i = 0; i < 5; i++) { + if (count < factor) { + break; + } + + count /= factor; + } + + QString unit; + switch (i) { + case 0: + decimal = 0; // no decimal + break; + case 1: + unit = tr("k", "e.g: 3.1 k"); + break; + case 2: + unit = tr("M", "e.g: 3.1 M"); + break; + case 3: + unit = tr("G", "e.g: 3.1 G"); + break; + default: // >= 4 + unit = tr("T", "e.g: 3.1 T"); + } + + return QString("%1 %2").arg(count, 0, 'f', decimal).arg(unit); +} + +QString misc::removeNewLine(const QString &text) +{ + return QString(text).replace("\n", " "); +} + +QString misc::removeNewLine(const std::string &text) +{ + return QString::fromUtf8(text.c_str()).replace("\n", " "); +} + +QString misc::removeNewLine(const std::wstring &text) +{ + return QString::fromStdWString(text).replace("\n", " "); +} + +bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file) +{ + QString lastDir = Settings->getLastDir(type); + + file = QFileDialog::getOpenFileName(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks); + + if (file.isEmpty() == false) { + lastDir = QFileInfo(file).absoluteDir().absolutePath(); + Settings->setLastDir(type, lastDir); + } + + return !file.isEmpty(); +} + +bool misc::getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files) +{ + QString lastDir = Settings->getLastDir(type); + + files = QFileDialog::getOpenFileNames(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks); + + if (files.isEmpty() == false) { + lastDir = QFileInfo(*files.begin()).absoluteDir().absolutePath(); + Settings->setLastDir(type, lastDir); + } + + return !files.isEmpty(); +} + +bool misc::getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file) +{ + QString lastDir = Settings->getLastDir(type); + + file = QFileDialog::getSaveFileName(parent, caption, lastDir, filter); + + if (file.isEmpty() == false) { + lastDir = QFileInfo(file).absoluteDir().absolutePath(); + Settings->setLastDir(type, lastDir); + } + + return !file.isEmpty(); +} diff --git a/retroshare-gui/src/util/misc.h b/retroshare-gui/src/util/misc.h index 850990e3d..16707e5d6 100644 --- a/retroshare-gui/src/util/misc.h +++ b/retroshare-gui/src/util/misc.h @@ -26,29 +26,17 @@ #include #include #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include - - +#include "gui/settings/rsharesettings.h" /* Miscellaneaous functions that can be useful */ -class misc : public QObject{ - Q_OBJECT +class misc : public QObject +{ + Q_OBJECT - public: + public: // Convert any type of variable to C++ String // convert=true will convert -1 to 0 template static std::string toString(const T& x, bool convert=false) { @@ -113,272 +101,65 @@ class misc : public QObject{ // use Binary prefix standards from IEC 60027-2 // see http://en.wikipedia.org/wiki/Kilobyte // value must be given in bytes - static QString friendlyUnit(float val) { - if(val < 0) { - return tr("Unknown", "Unknown (size)"); - } - const QString units[4] = {tr(" B", "bytes"), tr(" KiB", "kibibytes (1024 bytes)"), tr(" MiB", "mebibytes (1024 kibibytes)"), tr(" GiB", "gibibytes (1024 mibibytes)")}; - for(unsigned int i=0; i<5; ++i) { - if (val < 1024.) { - return QString(QByteArray::number(val, 'f', 1)) + units[i]; - } - val /= 1024.; - } - return QString(QByteArray::number(val, 'f', 1)) + tr(" TiB", "tebibytes (1024 gibibytes)"); - } + static QString friendlyUnit(float val); - static bool isPreviewable(QString extension){ - extension = extension.toUpper(); - if(extension == "AVI") return true; - if(extension == "MP3") return true; - if(extension == "OGG") return true; - if(extension == "OGM") return true; - if(extension == "WMV") return true; - if(extension == "WMA") return true; - if(extension == "MPEG") return true; - if(extension == "MPG") return true; - if(extension == "ASF") return true; - if(extension == "QT") return true; - if(extension == "RM") return true; - if(extension == "RMVB") return true; - if(extension == "RMV") return true; - if(extension == "SWF") return true; - if(extension == "FLV") return true; - if(extension == "WAV") return true; - if(extension == "MOV") return true; - if(extension == "VOB") return true; - if(extension == "MID") return true; - if(extension == "AC3") return true; - if(extension == "MP4") return true; - if(extension == "MP2") return true; - if(extension == "AVI") return true; - if(extension == "FLAC") return true; - if(extension == "AU") return true; - if(extension == "MPE") return true; - if(extension == "MOV") return true; - if(extension == "MKV") return true; - if(extension == "AIF") return true; - if(extension == "AIFF") return true; - if(extension == "AIFC") return true; - if(extension == "RA") return true; - if(extension == "RAM") return true; - if(extension == "M4P") return true; - if(extension == "M4A") return true; - if(extension == "3GP") return true; - if(extension == "AAC") return true; - if(extension == "SWA") return true; - if(extension == "MPC") return true; - if(extension == "MPP") return true; - return false; - } + static bool isPreviewable(QString extension); // return qBittorrent config path - static QString qBittorrentPath() { - QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator(); - // Create dir if it does not exist - if(!QFile::exists(qBtPath)){ - QDir dir(qBtPath); - dir.mkpath(qBtPath); - } - return qBtPath; - } - -// Not used anymore because it is not safe -// static bool removePath(QString path) { -// qDebug((QString::fromUtf8("file to delete:") + path).toUtf8()); -// if(!QFile::remove(path)) { -// // Probably a folder -// QDir current_dir(path); -// if(current_dir.exists()) { -// //Remove sub items -// QStringList subItems = current_dir.entryList(); -// QString item; -// foreach(item, subItems) { -// if(item != QString::fromUtf8(".") && item != QString::fromUtf8("..")) { -// qDebug("-> Removing "+(path+QDir::separator()+item).toUtf8()); -// removePath(path+QDir::separator()+item); -// } -// } -// // Remove empty folder -// if(current_dir.rmdir(path)) { -// return true; -// }else{ -// return false; -// } -// }else{ -// return false; -// } -// } -// return true; -// } - - static QString findFileInDir(QString dir_path, QString fileName) { - QDir dir(dir_path); - if(dir.exists(fileName)) { - return dir.filePath(fileName); - } - QStringList subDirs = dir.entryList(QDir::Dirs); - QString subdir_name; - foreach(subdir_name, subDirs) { - QString result = findFileInDir(dir.path()+QDir::separator()+subdir_name, fileName); - if(!result.isNull()) { - return result; - } - } - return QString(); - } + static QString qBittorrentPath(); + static QString findFileInDir(QString dir_path, QString fileName); // Insertion sort, used instead of bubble sort because it is // approx. 5 times faster. - template static void insertSort(QList > &list, const QPair& value, Qt::SortOrder sortOrder) { - int i = 0; - if(sortOrder == Qt::AscendingOrder) { - while(i < list.size() and value.second > list.at(i).second) { - ++i; - } - }else{ - while(i < list.size() and value.second < list.at(i).second) { - ++i; - } - } - list.insert(i, value); - } +// template static void insertSort(QList > &list, const QPair& value, Qt::SortOrder sortOrder) { +// int i = 0; +// if(sortOrder == Qt::AscendingOrder) { +// while(i < list.size() and value.second > list.at(i).second) { +// ++i; +// } +// }else{ +// while(i < list.size() and value.second < list.at(i).second) { +// ++i; +// } +// } +// list.insert(i, value); +// } - template static void insertSort2(QList > &list, const QPair& value, Qt::SortOrder sortOrder) { - int i = 0; - if(sortOrder == Qt::AscendingOrder) { - while(i < list.size() and value.first > list.at(i).first) { - ++i; - } - }else{ - while(i < list.size() and value.first < list.at(i).first) { - ++i; - } - } - list.insert(i, value); - } +// template static void insertSort2(QList > &list, const QPair& value, Qt::SortOrder sortOrder) { +// int i = 0; +// if(sortOrder == Qt::AscendingOrder) { +// while(i < list.size() and value.first > list.at(i).first) { +// ++i; +// } +// }else{ +// while(i < list.size() and value.first < list.at(i).first) { +// ++i; +// } +// } +// list.insert(i, value); +// } // Can't use template class for QString because >,< use unicode code for sorting // which is not what a human would expect when sorting strings. - static void insertSortString(QList > &list, QPair value, Qt::SortOrder sortOrder) { - int i = 0; - if(sortOrder == Qt::AscendingOrder) { - while(i < list.size() and QString::localeAwareCompare(value.second, list.at(i).second) > 0) { - ++i; - } - }else{ - while(i < list.size() and QString::localeAwareCompare(value.second, list.at(i).second) < 0) { - ++i; - } - } - list.insert(i, value); - } + static void insertSortString(QList > &list, QPair value, Qt::SortOrder sortOrder); - static float getPluginVersion(QString filePath) { - QFile plugin(filePath); - if(!plugin.exists()){ - qDebug("%s plugin does not exist, returning 0.0", filePath.toUtf8().data()); - return 0.0; - } - if(!plugin.open(QIODevice::ReadOnly | QIODevice::Text)){ - return 0.0; - } - float version = 0.0; - while (!plugin.atEnd()){ - QByteArray line = plugin.readLine(); - if(line.startsWith("#VERSION: ")){ - line = line.split(' ').last(); - line.replace("\n", ""); - version = line.toFloat(); - qDebug("plugin %s version: %.2f", filePath.toUtf8().data(), version); - break; - } - } - return version; - } + static float getPluginVersion(QString filePath); // Take a number of seconds and return an user-friendly // time duration like "1d 2h 10m". - static QString userFriendlyDuration(qlonglong seconds) - { - if(seconds < 0) { - return tr("Unknown"); - } - if(seconds < 60) { - return tr("< 1m", "< 1 minute"); - } - int minutes = seconds / 60; - if(minutes < 60) { - return tr("%1 minutes","e.g: 10minutes").arg(QString::QString::fromUtf8(misc::toString(minutes).c_str())); - } - int hours = minutes / 60; - minutes = minutes - hours*60; - if(hours < 24) { - return tr("%1h %2m", "e.g: 3hours 5minutes").arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str())); - } - int days = hours / 24; - hours = hours - days * 24; - if(days < 365) { - return tr("%1d %2h", "e.g: 2days 10hours").arg(QString::fromUtf8(misc::toString(days).c_str())).arg(QString::fromUtf8(misc::toString(hours).c_str())); - } - int years = days / 365; - days = days - years * 365; - return tr("%1y %2d", "e.g: 2 years 2days ").arg(QString::fromUtf8(misc::toString(years).c_str())).arg(QString::fromUtf8(misc::toString(days).c_str())); - } + static QString userFriendlyDuration(qlonglong seconds); - static QString userFriendlyUnit(double count, unsigned int decimal, double factor = 1000) - { - if (count <= 0.0) { - return "0"; - } + static QString userFriendlyUnit(double count, unsigned int decimal, double factor = 1000); - QString output; + static QString removeNewLine(const QString &text); + static QString removeNewLine(const std::string &text); + static QString removeNewLine(const std::wstring &text); - int i; - for (i = 0; i < 5; i++) { - if (count < factor) { - break; - } + static bool getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file); + static bool getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files); - count /= factor; - } - - QString unit; - switch (i) { - case 0: - decimal = 0; // no decimal - break; - case 1: - unit = tr("k", "e.g: 3.1 k"); - break; - case 2: - unit = tr("M", "e.g: 3.1 M"); - break; - case 3: - unit = tr("G", "e.g: 3.1 G"); - break; - default: // >= 4 - unit = tr("T", "e.g: 3.1 T"); - } - - return QString("%1 %2").arg(count, 0, 'f', decimal).arg(unit); - } - - static QString removeNewLine(const QString &text) - { - return QString(text).replace("\n", " "); - } - - static QString removeNewLine(const std::string &text) - { - return QString::fromUtf8(text.c_str()).replace("\n", " "); - } - - static QString removeNewLine(const std::wstring &text) - { - return QString::fromStdWString(text).replace("\n", " "); - } + static bool getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file); }; // Trick to get a portable sleep() function