Extracted a new widget ChatWidget for the basic chat handling from the PopupChatDialog and use it in ChatLobbyDialog too.

Added an own ui for the ChatLobbyDialog.
Saved settings of the ChatLobbyDialog.
Changed parameters of RsStatus interface from "std::string" to "const std::string&"
Fixed german language.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4806 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-01-17 20:36:36 +00:00
parent 7d7101a62d
commit 35c7605704
38 changed files with 3720 additions and 2552 deletions

View file

@ -16,14 +16,14 @@
*
* 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,
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QPixmap>
#include "PopupChatWindow.h"
#include "PopupChatDialog.h"
#include "ChatDialog.h"
#include "gui/settings/rsharesettings.h"
#include "gui/settings/RsharePeerSettings.h"
#include "gui/common/StatusDefs.h"
@ -41,334 +41,331 @@ static PopupChatWindow *instance = NULL;
/*static*/ PopupChatWindow *PopupChatWindow::getWindow(bool needSingleWindow)
{
if (needSingleWindow == false && (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW)) {
if (instance == NULL) {
instance = new PopupChatWindow(true);
}
if (needSingleWindow == false && (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW)) {
if (instance == NULL) {
instance = new PopupChatWindow(true);
}
return instance;
}
return instance;
}
return new PopupChatWindow(false);
return new PopupChatWindow(false);
}
/*static*/ void PopupChatWindow::cleanup()
{
if (instance) {
delete(instance);
instance = NULL;
}
if (instance) {
delete(instance);
instance = NULL;
}
}
/** Default constructor */
PopupChatWindow::PopupChatWindow(bool tabbed, QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
tabbedWindow = tabbed;
firstShow = true;
chatDialog = NULL;
tabbedWindow = tabbed;
firstShow = true;
chatDialog = NULL;
ui.tabWidget->setVisible(tabbedWindow);
ui.tabWidget->setVisible(tabbedWindow);
if (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW) {
ui.actionDockTab->setVisible(tabbedWindow == false);
ui.actionUndockTab->setVisible(tabbedWindow);
} else {
ui.actionDockTab->setVisible(false);
ui.actionUndockTab->setVisible(false);
}
if (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW) {
ui.actionDockTab->setVisible(tabbedWindow == false);
ui.actionUndockTab->setVisible(tabbedWindow);
} else {
ui.actionDockTab->setVisible(false);
ui.actionUndockTab->setVisible(false);
}
setAttribute(Qt::WA_DeleteOnClose, true);
setAttribute(Qt::WA_DeleteOnClose, true);
connect(ui.actionAvatar, SIGNAL(triggered()),this, SLOT(getAvatar()));
connect(ui.actionColor, SIGNAL(triggered()), this, SLOT(setStyle()));
connect(ui.actionDockTab, SIGNAL(triggered()), this, SLOT(dockTab()));
connect(ui.actionUndockTab, SIGNAL(triggered()), this, SLOT(undockTab()));
connect(ui.actionSetOnTop, SIGNAL(toggled(bool)), this, SLOT(setOnTop()));
connect(ui.actionAvatar, SIGNAL(triggered()),this, SLOT(getAvatar()));
connect(ui.actionColor, SIGNAL(triggered()), this, SLOT(setStyle()));
connect(ui.actionDockTab, SIGNAL(triggered()), this, SLOT(dockTab()));
connect(ui.actionUndockTab, SIGNAL(triggered()), this, SLOT(undockTab()));
connect(ui.actionSetOnTop, SIGNAL(toggled(bool)), this, SLOT(setOnTop()));
connect(ui.tabWidget, SIGNAL(tabChanged(PopupChatDialog*)), this, SLOT(tabChanged(PopupChatDialog*)));
connect(ui.tabWidget, SIGNAL(tabChanged(ChatDialog*)), this, SLOT(tabChanged(ChatDialog*)));
if (tabbedWindow) {
/* signal toggled is called */
ui.actionSetOnTop->setChecked(Settings->valueFromGroup("ChatWindow", "OnTop", false).toBool());
}
if (tabbedWindow) {
/* signal toggled is called */
ui.actionSetOnTop->setChecked(Settings->valueFromGroup("ChatWindow", "OnTop", false).toBool());
}
setWindowIcon(QIcon(IMAGE_WINDOW));
setWindowIcon(QIcon(IMAGE_WINDOW));
}
/** Destructor. */
PopupChatWindow::~PopupChatWindow()
{
saveSettings();
saveSettings();
if (this == instance) {
instance = NULL;
}
if (this == instance) {
instance = NULL;
}
}
void PopupChatWindow::saveSettings()
{
if (tabbedWindow) {
Settings->saveWidgetInformation(this);
if (tabbedWindow) {
Settings->saveWidgetInformation(this);
Settings->setValueToGroup("ChatWindow", "OnTop", ui.actionSetOnTop->isChecked());
} else {
if (!peerId.empty()) {
PeerSettings->saveWidgetInformation(peerId, this);
PeerSettings->setPrivateChatOnTop(peerId, ui.actionSetOnTop->isChecked());
}
}
Settings->setValueToGroup("ChatWindow", "OnTop", ui.actionSetOnTop->isChecked());
} else {
if (!peerId.empty()) {
PeerSettings->saveWidgetInformation(peerId, this);
PeerSettings->setPrivateChatOnTop(peerId, ui.actionSetOnTop->isChecked());
}
}
}
void PopupChatWindow::showEvent(QShowEvent */*event*/)
{
if (firstShow) {
firstShow = false;
if (firstShow) {
firstShow = false;
if (tabbedWindow) {
Settings->loadWidgetInformation(this);
} else {
this->move(qrand()%100, qrand()%100); //avoid to stack multiple popup chat windows on the same position
PeerSettings->loadWidgetInformation(peerId, this);
}
}
if (tabbedWindow) {
Settings->loadWidgetInformation(this);
} else {
this->move(qrand()%100, qrand()%100); //avoid to stack multiple popup chat windows on the same position
PeerSettings->loadWidgetInformation(peerId, this);
}
}
}
PopupChatDialog *PopupChatWindow::getCurrentDialog()
ChatDialog *PopupChatWindow::getCurrentDialog()
{
if (tabbedWindow) {
return dynamic_cast<PopupChatDialog*>(ui.tabWidget->currentWidget());
}
if (tabbedWindow) {
return dynamic_cast<ChatDialog*>(ui.tabWidget->currentWidget());
}
return chatDialog;
return chatDialog;
}
void PopupChatWindow::changeEvent(QEvent *event)
void PopupChatWindow::addDialog(ChatDialog *dialog)
{
if (event->type() == QEvent::ActivationChange) {
PopupChatDialog *pcd = getCurrentDialog();
if (pcd) {
pcd->activate();
}
}
if (tabbedWindow) {
ui.tabWidget->addDialog(dialog);
} else {
ui.horizontalLayout->addWidget(dialog);
dialog->addToParent(this);
ui.horizontalLayout->setContentsMargins(0, 0, 0, 0);
peerId = dialog->getPeerId();
chatDialog = dialog;
calculateStyle(dialog);
/* signal toggled is called */
ui.actionSetOnTop->setChecked(PeerSettings->getPrivateChatOnTop(peerId));
}
QObject::connect(dialog, SIGNAL(infoChanged(ChatDialog*)), this, SLOT(tabInfoChanged(ChatDialog*)));
QObject::connect(dialog, SIGNAL(newMessage(ChatDialog*)), this, SLOT(tabNewMessage(ChatDialog*)));
QObject::connect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
}
void PopupChatWindow::addDialog(PopupChatDialog *dialog)
void PopupChatWindow::removeDialog(ChatDialog *dialog)
{
if (tabbedWindow) {
ui.tabWidget->addDialog(dialog);
} else {
ui.horizontalLayout->addWidget(dialog);
ui.horizontalLayout->setContentsMargins(0, 0, 0, 0);
peerId = dialog->getPeerId();
chatDialog = dialog;
calculateStyle(dialog);
QObject::disconnect(dialog, SIGNAL(infoChanged(ChatDialog*)), this, SLOT(tabInfoChanged(ChatDialog*)));
QObject::disconnect(dialog, SIGNAL(newMessage(ChatDialog*)), this, SLOT(tabNewMessage(ChatDialog*)));
QObject::disconnect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
/* signal toggled is called */
ui.actionSetOnTop->setChecked(PeerSettings->getPrivateChatOnTop(peerId));
}
if (tabbedWindow) {
ui.tabWidget->removeDialog(dialog);
QObject::connect(dialog, SIGNAL(infoChanged(PopupChatDialog*)), this, SLOT(tabInfoChanged(PopupChatDialog*)));
QObject::connect(dialog, SIGNAL(newMessage(PopupChatDialog*)), this, SLOT(tabNewMessage(PopupChatDialog*)));
QObject::connect(dialog, SIGNAL(dialogClose(PopupChatDialog*)), this, SLOT(dialogClose(PopupChatDialog*)));
if (ui.tabWidget->count() == 0) {
deleteLater();
}
} else {
if (chatDialog == dialog) {
saveSettings();
dialog->removeFromParent(this);
ui.horizontalLayout->removeWidget(dialog);
chatDialog = NULL;
peerId.erase();
deleteLater();
}
}
}
void PopupChatWindow::removeDialog(PopupChatDialog *dialog)
void PopupChatWindow::showDialog(ChatDialog *dialog, uint chatflags)
{
QObject::disconnect(dialog, SIGNAL(infoChanged(PopupChatDialog*)), this, SLOT(tabInfoChanged(PopupChatDialog*)));
QObject::disconnect(dialog, SIGNAL(newMessage(PopupChatDialog*)), this, SLOT(tabNewMessage(PopupChatDialog*)));
QObject::disconnect(dialog, SIGNAL(dialogClose(PopupChatDialog*)), this, SLOT(dialogClose(PopupChatDialog*)));
if (tabbedWindow) {
ui.tabWidget->removeDialog(dialog);
if (ui.tabWidget->count() == 0) {
deleteLater();
}
} else {
if (chatDialog == dialog) {
saveSettings();
ui.horizontalLayout->removeWidget(dialog);
chatDialog = NULL;
peerId.erase();
deleteLater();
}
}
if (chatflags & RS_CHAT_FOCUS) {
if (tabbedWindow) {
ui.tabWidget->setCurrentWidget(dialog);
}
show();
activateWindow();
setWindowState((windowState() & (~Qt::WindowMinimized)) | Qt::WindowActive);
raise();
dialog->focusDialog();
} else {
if (isVisible() == false) {
showMinimized();
}
alertDialog(dialog);
}
}
void PopupChatWindow::showDialog(PopupChatDialog *dialog, uint chatflags)
void PopupChatWindow::alertDialog(ChatDialog */*dialog*/)
{
if (chatflags & RS_CHAT_FOCUS) {
if (tabbedWindow) {
ui.tabWidget->setCurrentWidget(dialog);
}
show();
activateWindow();
setWindowState((windowState() & (~Qt::WindowMinimized)) | Qt::WindowActive);
raise();
dialog->focusDialog();
} else {
if (isVisible() == false) {
showMinimized();
}
alertDialog(dialog);
}
QApplication::alert(this);
}
void PopupChatWindow::alertDialog(PopupChatDialog */*dialog*/)
void PopupChatWindow::calculateTitle(ChatDialog *dialog)
{
QApplication::alert(this);
}
bool hasNewMessages = false;
ChatDialog *cd;
void PopupChatWindow::calculateTitle(PopupChatDialog *dialog)
{
bool hasNewMessages = false;
PopupChatDialog *pcd;
/* is typing */
bool isTyping = false;
if (ui.tabWidget->isVisible()) {
ui.tabWidget->getInfo(isTyping, hasNewMessages, NULL);
} else {
if (dialog) {
isTyping = dialog->isTyping();
hasNewMessages = dialog->hasNewMessages();
}
}
/* is typing */
bool isTyping = false;
if (ui.tabWidget->isVisible()) {
ui.tabWidget->getInfo(isTyping, hasNewMessages, NULL);
} else {
if (dialog) {
isTyping = dialog->isTyping();
hasNewMessages = dialog->hasNewMessages();
}
}
if (ui.tabWidget->isVisible()) {
cd = dynamic_cast<ChatDialog*>(ui.tabWidget->currentWidget());
} else {
cd = dialog;
}
if (ui.tabWidget->isVisible()) {
pcd = dynamic_cast<PopupChatDialog*>(ui.tabWidget->currentWidget());
} else {
pcd = dialog;
}
QIcon icon;
if (isTyping) {
icon = QIcon(IMAGE_TYPING);
} else if (hasNewMessages) {
icon = QIcon(IMAGE_CHAT);
} else {
if (cd && cd->hasPeerStatus()) {
icon = QIcon(StatusDefs::imageIM(cd->getPeerStatus()));
} else {
icon = QIcon(IMAGE_WINDOW);
}
}
QIcon icon;
if (isTyping) {
icon = QIcon(IMAGE_TYPING);
} else if (hasNewMessages) {
icon = QIcon(IMAGE_CHAT);
} else {
if (pcd && pcd->hasPeerStatus()) {
icon = QIcon(StatusDefs::imageIM(pcd->getPeerStatus()));
} else {
icon = QIcon(IMAGE_WINDOW);
}
}
setWindowIcon(icon);
setWindowIcon(icon);
if (pcd) {
setWindowTitle(pcd->getTitle() + " (" + StatusDefs::name(pcd->getPeerStatus()) + ")");
} else {
setWindowTitle(tr("RetroShare"));
}
if (cd) {
QString title = cd->getTitle();
if (cd->hasPeerStatus()) {
title += " (" + StatusDefs::name(cd->getPeerStatus()) + ")";
}
setWindowTitle(title);
} else {
setWindowTitle("RetroShare");
}
}
void PopupChatWindow::getAvatar()
{
QByteArray ba;
if (misc::getOpenAvatarPicture(this, ba)) {
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
QByteArray ba;
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.
}
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()); // last char 0 included.
}
}
void PopupChatWindow::dialogClose(PopupChatDialog *dialog)
void PopupChatWindow::dialogClose(ChatDialog *dialog)
{
removeDialog(dialog);
removeDialog(dialog);
}
void PopupChatWindow::tabChanged(PopupChatDialog *dialog)
void PopupChatWindow::tabChanged(ChatDialog *dialog)
{
calculateStyle(dialog);
calculateTitle(dialog);
calculateStyle(dialog);
calculateTitle(dialog);
}
void PopupChatWindow::tabInfoChanged(PopupChatDialog *dialog)
void PopupChatWindow::tabInfoChanged(ChatDialog *dialog)
{
calculateTitle(dialog);
calculateTitle(dialog);
}
void PopupChatWindow::tabNewMessage(PopupChatDialog *dialog)
void PopupChatWindow::tabNewMessage(ChatDialog *dialog)
{
alertDialog(dialog);
alertDialog(dialog);
}
void PopupChatWindow::dockTab()
{
if ((Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW) && chatDialog) {
PopupChatWindow *pcw = getWindow(false);
if (pcw) {
PopupChatDialog *pcd = chatDialog;
removeDialog(pcd);
pcw->addDialog(pcd);
pcw->show();
pcw->calculateTitle(pcd);
}
}
if ((Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW) && chatDialog) {
PopupChatWindow *pcw = getWindow(false);
if (pcw) {
ChatDialog *pcd = chatDialog;
removeDialog(pcd);
pcw->addDialog(pcd);
pcw->show();
pcw->calculateTitle(pcd);
}
}
}
void PopupChatWindow::undockTab()
{
PopupChatDialog *pcd = dynamic_cast<PopupChatDialog*>(ui.tabWidget->currentWidget());
ChatDialog *cd = dynamic_cast<ChatDialog*>(ui.tabWidget->currentWidget());
if (pcd) {
PopupChatWindow *pcw = getWindow(true);
if (pcw) {
removeDialog(pcd);
pcw->addDialog(pcd);
pcd->show();
pcw->show();
pcw->calculateTitle(pcd);
}
}
if (cd) {
PopupChatWindow *pcw = getWindow(true);
if (pcw) {
removeDialog(cd);
pcw->addDialog(cd);
cd->show();
pcw->show();
pcw->calculateTitle(cd);
}
}
}
void PopupChatWindow::setStyle()
{
PopupChatDialog *pcd = getCurrentDialog();
ChatDialog *cd = getCurrentDialog();
if (pcd && pcd->setStyle()) {
calculateStyle(pcd);
}
if (cd && cd->setStyle()) {
calculateStyle(cd);
}
}
void PopupChatWindow::setOnTop()
{
Qt::WindowFlags flags = windowFlags();
if (ui.actionSetOnTop->isChecked()) {
flags |= Qt::WindowStaysOnTopHint;
} else {
flags &= ~Qt::WindowStaysOnTopHint;
}
setWindowFlags(flags);
Qt::WindowFlags flags = windowFlags();
if (ui.actionSetOnTop->isChecked()) {
flags |= Qt::WindowStaysOnTopHint;
} else {
flags &= ~Qt::WindowStaysOnTopHint;
}
setWindowFlags(flags);
/* Show window again */
show();
/* Show window again */
show();
}
void PopupChatWindow::calculateStyle(PopupChatDialog *dialog)
void PopupChatWindow::calculateStyle(ChatDialog *dialog)
{
QString toolSheet;
QString statusSheet;
QString widgetSheet;
QString toolSheet;
QString statusSheet;
QString widgetSheet;
if (dialog) {
const RSStyle &style = dialog->getStyle();
if (dialog) {
const RSStyle *style = dialog->getStyle();
if (style) {
QString styleSheet = style->getStyleSheet();
QString styleSheet = style.getStyleSheet();
if (styleSheet.isEmpty() == false) {
toolSheet = QString("QToolBar{%1}").arg(styleSheet);
statusSheet = QString(".QStatusBar{%1}").arg(styleSheet);
widgetSheet = QString(".QWidget{%1}").arg(styleSheet);
}
}
}
if (styleSheet.isEmpty() == false) {
toolSheet = QString("QToolBar{%1}").arg(styleSheet);
statusSheet = QString(".QStatusBar{%1}").arg(styleSheet);
widgetSheet = QString(".QWidget{%1}").arg(styleSheet);
}
}
ui.chattoolBar->setStyleSheet(toolSheet);
ui.chatstatusbar->setStyleSheet(statusSheet);
ui.chatcentralwidget->setStyleSheet(widgetSheet);
ui.chattoolBar->setStyleSheet(toolSheet);
ui.chatstatusbar->setStyleSheet(statusSheet);
ui.chatcentralwidget->setStyleSheet(widgetSheet);
}