Applied patch from AsamK and fixed german translation.

Reduced code duplication with avatar picture loading, by creating two new functions that handle image choosing and thumbnail creation.

two new functions:
bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data)
QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height)

getOpenThumbnailedPicture opens a QFileDialog to let the user choose a picture file. This picture is converted to a thumbnail and returned as a QPixmap.

getOpenAvatarPicture calls getOpenThumbnailedPicture and converts the result to a PNG byte array.

All three avatar loading functions now call getOpenAvatarPicture
Furthermore Channel Logo and Channel Msg thumbnail functions now use getOpenThumbnailedPicture

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4561 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-08-12 20:27:05 +00:00
parent 43c0594d18
commit 0fbada0eba
12 changed files with 666 additions and 212 deletions

View File

@ -1810,39 +1810,17 @@ void FriendsDialog::updateAvatar()
void FriendsDialog::getAvatar()
{
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);
#ifdef FRIENDS_DEBUG
std::cerr << "Sending avatar image down the pipe" << std::endl ;
#endif
// send avatar down the pipe for other peers to get it.
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
if (misc::getOpenAvatarPicture(this, ba))
{
#ifdef FRIENDS_DEBUG
std::cerr << "Image size = " << ba.size() << std::endl ;
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
#endif
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
// I suppressed this because it gets called already by rsMsgs->setOwnAvatarData() through a Qt notification signal
//updateAvatar() ;
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
}
}
void FriendsDialog::changeAvatarClicked()
{
updateAvatar();
}
void FriendsDialog::on_actionCreate_New_Forum_activated()
{
MainWindow::activatePage (MainWindow::Forums);

View File

@ -145,7 +145,6 @@ private slots:
void setFont();
void getFont();
void changeAvatarClicked();
void getAvatar();
void updateOwnStatus(const QString &peer_id, int status);

View File

@ -23,7 +23,6 @@
#include <QFileInfo>
#include <QWidgetAction>
#include <QTimer>
#include <QBuffer>
#include "common/vmessagebox.h"
#include "common/StatusDefs.h"
@ -51,6 +50,7 @@
#include "util/PixmapMerging.h"
#include "LogoBar.h"
#include "util/Widget.h"
#include "util/misc.h"
#include "settings/rsharesettings.h"
#include "common/RSTreeWidgetItem.h"
@ -1085,11 +1085,6 @@ void MessengerWindow::sendMessage()
MessageComposer::msgFriend(id, false);
}
void MessengerWindow::changeAvatarClicked()
{
updateAvatar();
}
void MessengerWindow::updateAvatar()
{
unsigned char *data = NULL;
@ -1112,24 +1107,13 @@ void MessengerWindow::updateAvatar()
void MessengerWindow::getAvatar()
{
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
if(!fileName.isEmpty())
{
picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
std::cerr << "Sending avatar image down the pipe" << std::endl ;
// send avatar down the pipe for other peers to get it.
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
std::cerr << "Image size = " << ba.size() << std::endl ;
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
updateAvatar() ;
if (misc::getOpenAvatarPicture(this, ba))
{
#ifdef MSG_DEBUG
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
#endif
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
}
}

View File

@ -91,7 +91,6 @@ private slots:
/** get own last stored Avatar**/
void getAvatar();
void changeAvatarClicked();
void updateOwnStatus(const QString &peer_id, int status);
void savestatusmessage();

View File

@ -241,14 +241,15 @@ void CreateChannel::cancelChannel()
return;
}
void CreateChannel::addChannelLogo()
void CreateChannel::addChannelLogo() // the same function as in EditChanDetails
{
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);
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
if (img.isNull())
return;
picture = img;
// to show the selected
ui.ChannelLogoButton->setIcon(picture);
}
}

View File

@ -571,24 +571,13 @@ void CreateChannelMsg::sendMessage(std::wstring subject, std::wstring msg, std::
void CreateChannelMsg::addThumbnail()
{
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);
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load thumbnail picture"), 156, 107);
if (img.isNull())
return;
picture = img;
// to show the selected
thumbnail_label->setPixmap(picture);
std::cerr << "Sending Thumbnail image down the pipe" << std::endl ;
// send Thumbnail down the pipe for other peers to get it.
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
std::cerr << "Image size = " << ba.size() << std::endl ;
//updateThumbnail() ;
}
}

View File

@ -135,15 +135,16 @@ void EditChanDetails::applyDialog()
}
void EditChanDetails::addChannelLogo()
void EditChanDetails::addChannelLogo() // the same function as in CreateChannel
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), QDir::homePath(), tr("Pictures (*.png *.xpm *.jpg)"));
if(!fileName.isEmpty())
{
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
if (img.isNull())
return;
picture = img;
// to show the selected
ui.ChannelLogoButton->setIcon(picture);
}
}

View File

@ -21,7 +21,6 @@
****************************************************************/
#include <QPixmap>
#include <QBuffer>
#include "PopupChatWindow.h"
#include "PopupChatDialog.h"
@ -291,20 +290,10 @@ void PopupChatWindow::calculateTitle(PopupChatDialog *dialog)
void PopupChatWindow::getAvatar()
{
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;
// send avatar down the pipe for other peers to get it.
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
std::cerr << "Image size = " << ba.size() << std::endl;
if (misc::getOpenAvatarPicture(this, ba))
{
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()); // last char 0 included.
}

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,8 @@
#include <QString>
#include <QDir>
#include <QFileDialog>
#include <QByteArray>
#include <QBuffer>
#include "misc.h"
@ -243,6 +245,43 @@ QString misc::removeNewLine(const std::wstring &text)
return QString::fromStdWString(text).replace("\n", " ");
}
/*!
* Let's the user choose an avatar picture file, which is returned as a PNG thumbnail
* in a byte array
*
* return false, if the user canceled the dialog, otherwise true
*/
bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data)
{
QPixmap picture = getOpenThumbnailedPicture(parent, tr("Load avatar image"), 96, 96);
if (picture.isNull())
return false;
// save image in QByteArray
QBuffer buffer(&image_data);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
return true;
}
/*!
* Open a QFileDialog to let the user choose a picture file.
* This picture is converted to a thumbnail and returned as a QPixmap.
*
* \return a null pixmap, if the user canceled the dialog, otherwise the chosen picture
*/
QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height)
{
// Let the user choose an picture file
QString fileName;
if (!getOpenFileName(parent, RshareSettings::LASTDIR_IMAGES, caption, tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
return QPixmap();
return QPixmap(fileName).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file)
{
QString lastDir = Settings->getLastDir(type);

View File

@ -156,6 +156,8 @@ class misc : public QObject
static QString removeNewLine(const std::string &text);
static QString removeNewLine(const std::wstring &text);
static bool getOpenAvatarPicture(QWidget *parent, QByteArray &image_data);
static QPixmap getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height);
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);