2010-05-03 17:17:36 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 - 2010 RetroShare Team
*
* 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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-23 14:52:58 -04:00
# include <QFontDialog>
2013-06-16 10:39:44 -04:00
# include <QMenu>
# include <QMessageBox>
2010-09-07 11:49:31 -04:00
# include <time.h>
2010-05-03 17:17:36 -04:00
2012-10-27 11:51:34 -04:00
# include <retroshare/rsnotify.h>
2013-06-16 10:39:44 -04:00
# include <retroshare/rsmsgs.h>
# include <retroshare/rspeers.h>
2010-05-03 17:17:36 -04:00
# include "ChatPage.h"
2013-06-16 10:39:44 -04:00
# include <gui/RetroShareLink.h>
# include <gui/CreateMsgLinkDialog.h>
2010-09-07 11:49:31 -04:00
# include "gui/chat/ChatStyle.h"
2013-06-16 10:39:44 -04:00
# include "gui/chat/ChatDialog.h"
2010-09-07 11:49:31 -04:00
# include "gui/notifyqt.h"
2010-07-23 14:52:58 -04:00
# include "rsharesettings.h"
2011-09-29 05:20:09 -04:00
# include <retroshare/rshistory.h>
2011-12-26 17:43:54 -05:00
# include <retroshare/rsmsgs.h>
2011-09-29 05:20:09 -04:00
2010-09-07 19:19:27 -04:00
# define VARIANT_STANDARD "Standard"
2013-06-16 10:39:44 -04:00
# define IMAGE_CHAT_CREATE ": / images / add_24x24.png"
# define IMAGE_CHAT_OPEN ": / images / typing.png"
# define IMAGE_CHAT_DELETE ": / images / deletemail24.png"
# define IMAGE_CHAT_COPY ": / images / copyrslink.png"
2010-09-07 19:19:27 -04:00
static QString loadStyleInfo ( ChatStyle : : enumStyleType type , QListWidget * listWidget , QComboBox * comboBox , QString & styleVariant )
2010-09-07 11:49:31 -04:00
{
QList < ChatStyleInfo > styles ;
QList < ChatStyleInfo > : : iterator style ;
QListWidgetItem * item ;
QListWidgetItem * activeItem = NULL ;
QString stylePath ;
switch ( type ) {
case ChatStyle : : TYPE_PUBLIC :
2010-09-07 19:19:27 -04:00
Settings - > getPublicChatStyle ( stylePath , styleVariant ) ;
2010-09-07 11:49:31 -04:00
break ;
case ChatStyle : : TYPE_PRIVATE :
2010-09-07 19:19:27 -04:00
Settings - > getPrivateChatStyle ( stylePath , styleVariant ) ;
2010-09-07 11:49:31 -04:00
break ;
case ChatStyle : : TYPE_HISTORY :
2010-09-07 19:19:27 -04:00
Settings - > getHistoryChatStyle ( stylePath , styleVariant ) ;
2010-09-07 11:49:31 -04:00
break ;
case ChatStyle : : TYPE_UNKNOWN :
return " " ;
}
ChatStyle : : getAvailableStyles ( type , styles ) ;
for ( style = styles . begin ( ) ; style ! = styles . end ( ) ; style + + ) {
item = new QListWidgetItem ( style - > styleName ) ;
item - > setData ( Qt : : UserRole , qVariantFromValue ( * style ) ) ;
listWidget - > addItem ( item ) ;
if ( style - > stylePath = = stylePath ) {
activeItem = item ;
}
}
listWidget - > setCurrentItem ( activeItem ) ;
2010-09-07 19:19:27 -04:00
/* now the combobox should be filled */
int index = comboBox - > findText ( styleVariant ) ;
if ( index ! = - 1 ) {
comboBox - > setCurrentIndex ( index ) ;
} else {
if ( comboBox - > count ( ) ) {
comboBox - > setCurrentIndex ( 0 ) ;
}
}
2010-09-07 11:49:31 -04:00
return stylePath ;
}
2010-05-03 17:17:36 -04:00
/** Constructor */
ChatPage : : ChatPage ( QWidget * parent , Qt : : WFlags flags )
: ConfigPage ( parent , flags )
{
2010-09-07 11:49:31 -04:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2010-05-03 17:17:36 -04:00
2012-09-24 07:32:11 -04:00
# if QT_VERSION < 0x040600
ui . minimumContrastLabel - > hide ( ) ;
ui . minimumContrast - > hide ( ) ;
# endif
2013-06-16 10:39:44 -04:00
connect ( ui . _personal_invites_LW , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( personalInvites_customPopupMenu ( QPoint ) ) ) ;
connect ( ui . _collected_contacts_LW , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( collectedContacts_customPopupMenu ( QPoint ) ) ) ;
2010-09-07 11:49:31 -04:00
/* Hide platform specific features */
2010-05-03 17:17:36 -04:00
# ifdef Q_WS_WIN
# endif
}
2013-06-16 10:39:44 -04:00
void ChatPage : : collectedContacts_customPopupMenu ( QPoint p )
{
// items: chat with this person, copy to clipboard, delete
std : : cerr < < " In custom popup menu " < < std : : endl ;
QListWidgetItem * item = ui . _collected_contacts_LW - > itemAt ( p ) ;
if ( item = = NULL )
return ;
QList < QListWidgetItem * > selected = ui . _collected_contacts_LW - > selectedItems ( ) ;
QMenu contextMnu ( this ) ;
if ( selected . size ( ) = = 1 )
contextMnu . addAction ( QIcon ( IMAGE_CHAT_OPEN ) , tr ( " Open secured chat tunnel " ) , this , SLOT ( collectedInvite_openDistantChat ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_CHAT_DELETE ) , tr ( " Delete this invite " ) , this , SLOT ( collectedInvite_delete ( ) ) ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
void ChatPage : : collectedInvite_openDistantChat ( )
{
QList < QListWidgetItem * > selected = ui . _collected_contacts_LW - > selectedItems ( ) ;
std : : string hash = ( * selected . begin ( ) ) - > data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ;
std : : cerr < < " Openning secured chat tunnel for hash " < < hash < < " . Please wait... " < < std : : endl ;
uint32_t error_code ;
if ( ! rsMsgs - > initiateDistantChatConnexion ( hash , error_code ) )
QMessageBox : : critical ( NULL , tr ( " Can't open distant chat " ) , tr ( " Cannot open distant chat. Error code= " ) + QString : : number ( error_code ) ) ;
else
ChatDialog : : chatFriend ( hash ) ;
}
void ChatPage : : collectedInvite_delete ( )
{
QList < QListWidgetItem * > selected = ui . _collected_contacts_LW - > selectedItems ( ) ;
for ( QList < QListWidgetItem * > : : const_iterator it ( selected . begin ( ) ) ; it ! = selected . end ( ) ; + + it )
{
std : : string hash = ( * it ) - > data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ;
std : : cerr < < " Removing chat invite for hash " < < hash < < std : : endl ;
if ( ! rsMsgs - > removeDistantChatInvite ( hash ) )
QMessageBox : : critical ( NULL , tr ( " Can't open distant chat " ) , tr ( " Cannot remove distant chat invite. " ) ) ;
}
load ( ) ;
}
void ChatPage : : personalInvites_customPopupMenu ( QPoint p )
{
// items: create invite, copy to clipboard, delete
std : : cerr < < " In custom popup menu " < < std : : endl ;
QList < QListWidgetItem * > selected = ui . _personal_invites_LW - > selectedItems ( ) ;
QMenu contextMnu ( this ) ;
contextMnu . addAction ( QIcon ( IMAGE_CHAT_CREATE ) , tr ( " Create a chat invitation " ) , this , SLOT ( personalInvites_create ( ) ) ) ;
if ( ! selected . empty ( ) )
{
contextMnu . addAction ( QIcon ( IMAGE_CHAT_COPY ) , tr ( " Copy link to clipboard " ) , this , SLOT ( personalInvites_copyLink ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_CHAT_DELETE ) , tr ( " Delete this invite " ) , this , SLOT ( personalInvites_delete ( ) ) ) ;
}
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
void ChatPage : : personalInvites_copyLink ( )
{
QList < QListWidgetItem * > selected = ui . _personal_invites_LW - > selectedItems ( ) ;
QList < RetroShareLink > links ;
std : : vector < DistantChatInviteInfo > invites ;
rsMsgs - > getDistantChatInviteList ( invites ) ;
for ( QList < QListWidgetItem * > : : const_iterator it ( selected . begin ( ) ) ; it ! = selected . end ( ) ; + + it )
{
std : : string hash = ( * it ) - > data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ;
bool found = false ;
for ( uint32_t i = 0 ; i < invites . size ( ) ; + + i )
if ( invites [ i ] . hash = = hash )
{
RetroShareLink link ;
if ( ! link . createPrivateChatInvite ( invites [ i ] . time_of_validity , QString : : fromStdString ( invites [ i ] . destination_pgp_id ) , QString : : fromStdString ( invites [ i ] . encrypted_radix64_string ) ) )
{
std : : cerr < < " Cannot create link. " < < std : : endl ;
continue ;
}
links . push_back ( link ) ;
break ;
}
}
if ( ! links . empty ( ) )
RSLinkClipboard : : copyLinks ( links ) ;
}
void ChatPage : : personalInvites_delete ( )
{
QList < QListWidgetItem * > selected = ui . _personal_invites_LW - > selectedItems ( ) ;
QList < RetroShareLink > links ;
for ( QList < QListWidgetItem * > : : const_iterator it ( selected . begin ( ) ) ; it ! = selected . end ( ) ; + + it )
{
std : : string hash = ( * it ) - > data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ;
rsMsgs - > removeDistantChatInvite ( hash ) ;
}
load ( ) ;
}
void ChatPage : : personalInvites_create ( )
{
// Call the link creation box
CreateMsgLinkDialog : : createNewChatLink ( ) ;
// Now update the page
//
load ( ) ;
}
2010-05-03 17:17:36 -04:00
/** Saves the changes on this page */
bool
2011-08-12 10:06:29 -04:00
ChatPage : : save ( QString & /*errmsg*/ )
2010-05-03 17:17:36 -04:00
{
2010-09-04 10:23:30 -04:00
Settings - > beginGroup ( QString ( " Chat " ) ) ;
2012-09-21 17:23:14 -04:00
Settings - > setValue ( " Emoteicons_PrivatChat " , ui . checkBox_emoteprivchat - > isChecked ( ) ) ;
Settings - > setValue ( " Emoteicons_GroupChat " , ui . checkBox_emotegroupchat - > isChecked ( ) ) ;
Settings - > setValue ( " EnableCustomFonts " , ui . checkBox_enableCustomFonts - > isChecked ( ) ) ;
Settings - > setValue ( " EnableCustomFontSize " , ui . checkBox_enableCustomFontSize - > isChecked ( ) ) ;
Settings - > setValue ( " EnableBold " , ui . checkBox_enableBold - > isChecked ( ) ) ;
Settings - > setValue ( " EnableItalics " , ui . checkBox_enableItalics - > isChecked ( ) ) ;
Settings - > setValue ( " MinimumContrast " , ui . minimumContrast - > value ( ) ) ;
2010-09-04 10:23:30 -04:00
Settings - > endGroup ( ) ;
2010-05-18 14:02:51 -04:00
2010-09-10 14:38:46 -04:00
Settings - > setChatScreenFont ( fontTempChat . toString ( ) ) ;
2010-09-04 10:23:30 -04:00
Settings - > setChatSendMessageWithCtrlReturn ( ui . sendMessageWithCtrlReturn - > isChecked ( ) ) ;
2011-09-29 05:20:09 -04:00
Settings - > setPublicChatHistoryCount ( ui . publicChatLoadCount - > value ( ) ) ;
Settings - > setPrivateChatHistoryCount ( ui . privateChatLoadCount - > value ( ) ) ;
rsHistory - > setEnable ( true , ui . publicChatEnable - > isChecked ( ) ) ;
rsHistory - > setEnable ( false , ui . privateChatEnable - > isChecked ( ) ) ;
rsHistory - > setSaveCount ( true , ui . publicChatSaveCount - > value ( ) ) ;
rsHistory - > setSaveCount ( false , ui . privateChatSaveCount - > value ( ) ) ;
2010-11-04 07:14:47 -04:00
2012-02-03 08:29:16 -05:00
rsMsgs - > setDefaultNickNameForChatLobby ( ui . chatLobbyNick_LE - > text ( ) . toUtf8 ( ) . constData ( ) ) ;
2011-12-26 17:43:54 -05:00
2010-09-07 11:49:31 -04:00
ChatStyleInfo info ;
QListWidgetItem * item = ui . publicList - > currentItem ( ) ;
if ( item ) {
info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
2010-09-07 19:19:27 -04:00
if ( publicStylePath ! = info . stylePath | | publicStyleVariant ! = ui . publicComboBoxVariant - > currentText ( ) ) {
Settings - > setPublicChatStyle ( info . stylePath , ui . publicComboBoxVariant - > currentText ( ) ) ;
2010-09-07 11:49:31 -04:00
NotifyQt : : getInstance ( ) - > notifyChatStyleChanged ( ChatStyle : : TYPE_PUBLIC ) ;
}
}
item = ui . privateList - > currentItem ( ) ;
if ( item ) {
info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
2010-09-07 19:19:27 -04:00
if ( privateStylePath ! = info . stylePath | | privateStyleVariant ! = ui . privateComboBoxVariant - > currentText ( ) ) {
Settings - > setPrivateChatStyle ( info . stylePath , ui . privateComboBoxVariant - > currentText ( ) ) ;
2010-09-07 11:49:31 -04:00
NotifyQt : : getInstance ( ) - > notifyChatStyleChanged ( ChatStyle : : TYPE_PRIVATE ) ;
}
}
item = ui . historyList - > currentItem ( ) ;
if ( item ) {
info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
2010-09-07 19:19:27 -04:00
if ( historyStylePath ! = info . stylePath | | historyStyleVariant ! = ui . historyComboBoxVariant - > currentText ( ) ) {
Settings - > setHistoryChatStyle ( info . stylePath , ui . historyComboBoxVariant - > currentText ( ) ) ;
2010-09-07 11:49:31 -04:00
NotifyQt : : getInstance ( ) - > notifyChatStyleChanged ( ChatStyle : : TYPE_HISTORY ) ;
}
}
2012-10-27 11:51:34 -04:00
uint chatflags = 0 ;
if ( ui . chat_NewWindow - > isChecked ( ) )
chatflags | = RS_CHAT_OPEN ;
if ( ui . chat_Focus - > isChecked ( ) )
chatflags | = RS_CHAT_FOCUS ;
if ( ui . chat_tabbedWindow - > isChecked ( ) )
chatflags | = RS_CHAT_TABBED_WINDOW ;
2012-10-27 11:59:12 -04:00
if ( ui . chat_Blink - > isChecked ( ) )
chatflags | = RS_CHAT_BLINK ;
2012-10-27 11:51:34 -04:00
Settings - > setChatFlags ( chatflags ) ;
2012-10-27 11:59:12 -04:00
uint chatLobbyFlags = 0 ;
if ( ui . chatLobby_Blink - > isChecked ( ) )
chatLobbyFlags | = RS_CHATLOBBY_BLINK ;
Settings - > setChatLobbyFlags ( chatLobbyFlags ) ;
2010-09-04 10:23:30 -04:00
return true ;
2010-05-03 17:17:36 -04:00
}
/** Loads the settings for this page */
void
ChatPage : : load ( )
{
2010-09-04 10:23:30 -04:00
Settings - > beginGroup ( QString ( " Chat " ) ) ;
2012-09-21 17:23:14 -04:00
ui . checkBox_emoteprivchat - > setChecked ( Settings - > value ( " Emoteicons_PrivatChat " , true ) . toBool ( ) ) ;
ui . checkBox_emotegroupchat - > setChecked ( Settings - > value ( " Emoteicons_GroupChat " , true ) . toBool ( ) ) ;
ui . checkBox_enableCustomFonts - > setChecked ( Settings - > value ( " EnableCustomFonts " , true ) . toBool ( ) ) ;
ui . checkBox_enableCustomFontSize - > setChecked ( Settings - > value ( " EnableCustomFontSize " , true ) . toBool ( ) ) ;
ui . checkBox_enableBold - > setChecked ( Settings - > value ( " EnableBold " , true ) . toBool ( ) ) ;
ui . checkBox_enableItalics - > setChecked ( Settings - > value ( " EnableItalics " , true ) . toBool ( ) ) ;
ui . minimumContrast - > setValue ( Settings - > value ( " MinimumContrast " , 4.5 ) . toDouble ( ) ) ;
2010-09-04 10:23:30 -04:00
Settings - > endGroup ( ) ;
2010-05-03 17:17:36 -04:00
2010-09-10 14:38:46 -04:00
fontTempChat . fromString ( Settings - > getChatScreenFont ( ) ) ;
2010-09-04 10:23:30 -04:00
ui . sendMessageWithCtrlReturn - > setChecked ( Settings - > getChatSendMessageWithCtrlReturn ( ) ) ;
2010-05-03 17:17:36 -04:00
2011-09-29 05:20:09 -04:00
ui . publicChatLoadCount - > setValue ( Settings - > getPublicChatHistoryCount ( ) ) ;
ui . privateChatLoadCount - > setValue ( Settings - > getPrivateChatHistoryCount ( ) ) ;
ui . publicChatEnable - > setChecked ( rsHistory - > getEnable ( true ) ) ;
ui . privateChatEnable - > setChecked ( rsHistory - > getEnable ( false ) ) ;
ui . publicChatSaveCount - > setValue ( rsHistory - > getSaveCount ( true ) ) ;
ui . privateChatSaveCount - > setValue ( rsHistory - > getSaveCount ( false ) ) ;
2010-11-04 07:14:47 -04:00
2010-09-04 10:23:30 -04:00
ui . labelChatFontPreview - > setText ( fontTempChat . rawName ( ) ) ;
ui . labelChatFontPreview - > setFont ( fontTempChat ) ;
2010-09-07 11:49:31 -04:00
/* Load styles */
2010-09-07 19:19:27 -04:00
publicStylePath = loadStyleInfo ( ChatStyle : : TYPE_PUBLIC , ui . publicList , ui . publicComboBoxVariant , publicStyleVariant ) ;
privateStylePath = loadStyleInfo ( ChatStyle : : TYPE_PRIVATE , ui . privateList , ui . privateComboBoxVariant , privateStyleVariant ) ;
historyStylePath = loadStyleInfo ( ChatStyle : : TYPE_HISTORY , ui . historyList , ui . historyComboBoxVariant , historyStyleVariant ) ;
2011-12-26 17:43:54 -05:00
2012-02-03 08:29:16 -05:00
std : : string nick ;
rsMsgs - > getDefaultNickNameForChatLobby ( nick ) ;
ui . chatLobbyNick_LE - > setText ( QString : : fromUtf8 ( nick . c_str ( ) ) ) ;
2012-10-27 11:51:34 -04:00
uint chatflags = Settings - > getChatFlags ( ) ;
ui . chat_NewWindow - > setChecked ( chatflags & RS_CHAT_OPEN ) ;
ui . chat_Focus - > setChecked ( chatflags & RS_CHAT_FOCUS ) ;
ui . chat_tabbedWindow - > setChecked ( chatflags & RS_CHAT_TABBED_WINDOW ) ;
2012-10-27 11:59:12 -04:00
ui . chat_Blink - > setChecked ( chatflags & RS_CHAT_BLINK ) ;
uint chatLobbyFlags = Settings - > getChatLobbyFlags ( ) ;
ui . chatLobby_Blink - > setChecked ( chatLobbyFlags & RS_CHATLOBBY_BLINK ) ;
2013-06-16 10:39:44 -04:00
// load personal invites
//
std : : vector < DistantChatInviteInfo > invites ;
rsMsgs - > getDistantChatInviteList ( invites ) ;
ui . _personal_invites_LW - > clear ( ) ;
ui . _collected_contacts_LW - > clear ( ) ;
for ( uint32_t i = 0 ; i < invites . size ( ) ; + + i )
{
RsPeerDetails detail ;
rsPeers - > getPeerDetails ( invites [ i ] . destination_pgp_id , detail ) ;
if ( invites [ i ] . encrypted_radix64_string . empty ( ) )
{
QListWidgetItem * item = new QListWidgetItem ;
item - > setData ( Qt : : DisplayRole , tr ( " Private chat invite from " ) + QString : : fromStdString ( detail . name ) + " ( " + QString : : fromStdString ( invites [ i ] . destination_pgp_id ) + " , " + QString : : fromStdString ( detail . name ) + " , valid until " + QDateTime : : fromTime_t ( invites [ i ] . time_of_validity ) . toString ( ) + " ) " ) ;
item - > setData ( Qt : : UserRole , QString : : fromStdString ( invites [ i ] . hash ) ) ;
ui . _collected_contacts_LW - > insertItem ( 0 , item ) ;
}
else
{
QListWidgetItem * item = new QListWidgetItem ;
item - > setData ( Qt : : DisplayRole , tr ( " Private chat invite to " ) + QString : : fromStdString ( detail . name ) + " ( " + QString : : fromStdString ( invites [ i ] . destination_pgp_id ) + " , " + QString : : fromStdString ( detail . name ) + " , valid until " + QDateTime : : fromTime_t ( invites [ i ] . time_of_validity ) . toString ( ) + " ) " ) ;
item - > setData ( Qt : : UserRole , QString : : fromStdString ( invites [ i ] . hash ) ) ;
ui . _personal_invites_LW - > insertItem ( 0 , item ) ;
}
}
2010-05-03 17:17:36 -04:00
}
2010-05-14 08:42:31 -04:00
void ChatPage : : on_pushButtonChangeChatFont_clicked ( )
{
bool ok ;
QFont font = QFontDialog : : getFont ( & ok , fontTempChat , this ) ;
if ( ok ) {
fontTempChat = font ;
ui . labelChatFontPreview - > setText ( fontTempChat . rawName ( ) ) ;
ui . labelChatFontPreview - > setFont ( fontTempChat ) ;
}
}
2010-09-07 11:49:31 -04:00
2010-09-07 19:19:27 -04:00
void ChatPage : : setPreviewMessages ( QString & stylePath , QString styleVariant , QTextBrowser * textBrowser )
2010-09-07 11:49:31 -04:00
{
ChatStyle style ;
2010-09-07 19:19:27 -04:00
style . setStylePath ( stylePath , styleVariant ) ;
2010-09-07 11:49:31 -04:00
textBrowser - > clear ( ) ;
2012-01-30 19:06:24 -05:00
QString nameIncoming = tr ( " Incoming " ) ;
QString nameOutgoing = tr ( " Outgoing " ) ;
2010-09-07 11:49:31 -04:00
QDateTime timestmp = QDateTime : : fromTime_t ( time ( NULL ) ) ;
2012-01-30 19:06:24 -05:00
2012-05-11 20:40:53 -04:00
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_HINCOMING , nameIncoming , timestmp , tr ( " Incoming message in history " ) ) ) ;
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_HOUTGOING , nameOutgoing , timestmp , tr ( " Outgoing message in history " ) ) ) ;
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_INCOMING , nameIncoming , timestmp , tr ( " Incoming message " ) ) ) ;
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_OUTGOING , nameOutgoing , timestmp , tr ( " Outgoing message " ) ) ) ;
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_OOUTGOING , nameOutgoing , timestmp , tr ( " Outgoing offline message " ) ) ) ;
textBrowser - > append ( style . formatMessage ( ChatStyle : : FORMATMSG_SYSTEM , tr ( " System " ) , timestmp , tr ( " System message " ) ) ) ;
2010-09-07 11:49:31 -04:00
}
2010-09-07 19:19:27 -04:00
void ChatPage : : fillPreview ( QListWidget * listWidget , QComboBox * comboBox , QTextBrowser * textBrowser )
{
QListWidgetItem * item = listWidget - > currentItem ( ) ;
if ( item ) {
ChatStyleInfo info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
setPreviewMessages ( info . stylePath , comboBox - > currentText ( ) , textBrowser ) ;
} else {
textBrowser - > clear ( ) ;
}
}
2010-09-07 11:49:31 -04:00
void ChatPage : : on_publicList_currentRowChanged ( int currentRow )
{
if ( currentRow ! = - 1 ) {
QListWidgetItem * item = ui . publicList - > item ( currentRow ) ;
ChatStyleInfo info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
QString author = info . authorName ;
if ( info . authorEmail . isEmpty ( ) = = false ) {
author + = " ( " + info . authorEmail + " ) " ;
}
ui . publicAuthor - > setText ( author ) ;
ui . publicDescription - > setText ( info . styleDescription ) ;
2010-09-07 19:19:27 -04:00
QStringList variants ;
ChatStyle : : getAvailableVariants ( info . stylePath , variants ) ;
ui . publicComboBoxVariant - > clear ( ) ;
ui . publicComboBoxVariant - > setEnabled ( variants . size ( ) ! = 0 ) ;
ui . publicComboBoxVariant - > addItems ( variants ) ;
/* try to find "Standard" */
int index = ui . publicComboBoxVariant - > findText ( VARIANT_STANDARD ) ;
if ( index ! = - 1 ) {
ui . publicComboBoxVariant - > setCurrentIndex ( index ) ;
} else {
ui . publicComboBoxVariant - > setCurrentIndex ( 0 ) ;
}
2010-09-07 11:49:31 -04:00
} else {
ui . publicAuthor - > clear ( ) ;
ui . publicDescription - > clear ( ) ;
2010-09-07 19:19:27 -04:00
ui . publicComboBoxVariant - > clear ( ) ;
ui . publicComboBoxVariant - > setDisabled ( true ) ;
2010-09-07 11:49:31 -04:00
}
2010-09-07 19:19:27 -04:00
fillPreview ( ui . publicList , ui . publicComboBoxVariant , ui . publicPreview ) ;
2010-09-07 11:49:31 -04:00
}
void ChatPage : : on_privateList_currentRowChanged ( int currentRow )
{
if ( currentRow ! = - 1 ) {
QListWidgetItem * item = ui . privateList - > item ( currentRow ) ;
ChatStyleInfo info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
QString author = info . authorName ;
if ( info . authorEmail . isEmpty ( ) = = false ) {
author + = " ( " + info . authorEmail + " ) " ;
}
ui . privateAuthor - > setText ( author ) ;
ui . privateDescription - > setText ( info . styleDescription ) ;
2010-09-07 19:19:27 -04:00
QStringList variants ;
ChatStyle : : getAvailableVariants ( info . stylePath , variants ) ;
ui . privateComboBoxVariant - > clear ( ) ;
ui . privateComboBoxVariant - > setEnabled ( variants . size ( ) ! = 0 ) ;
ui . privateComboBoxVariant - > addItems ( variants ) ;
/* try to find "Standard" */
int index = ui . privateComboBoxVariant - > findText ( VARIANT_STANDARD ) ;
if ( index ! = - 1 ) {
ui . privateComboBoxVariant - > setCurrentIndex ( index ) ;
} else {
ui . privateComboBoxVariant - > setCurrentIndex ( 0 ) ;
}
2010-09-07 11:49:31 -04:00
} else {
ui . privateAuthor - > clear ( ) ;
ui . privateDescription - > clear ( ) ;
2010-09-07 19:19:27 -04:00
ui . privateComboBoxVariant - > clear ( ) ;
ui . privateComboBoxVariant - > setDisabled ( true ) ;
2010-09-07 11:49:31 -04:00
}
2010-09-07 19:19:27 -04:00
fillPreview ( ui . privateList , ui . privateComboBoxVariant , ui . privatePreview ) ;
2010-09-07 11:49:31 -04:00
}
void ChatPage : : on_historyList_currentRowChanged ( int currentRow )
{
if ( currentRow ! = - 1 ) {
QListWidgetItem * item = ui . historyList - > item ( currentRow ) ;
ChatStyleInfo info = qVariantValue < ChatStyleInfo > ( item - > data ( Qt : : UserRole ) ) ;
QString author = info . authorName ;
if ( info . authorEmail . isEmpty ( ) = = false ) {
author + = " ( " + info . authorEmail + " ) " ;
}
ui . historyAuthor - > setText ( author ) ;
ui . historyDescription - > setText ( info . styleDescription ) ;
2010-09-07 19:19:27 -04:00
QStringList variants ;
ChatStyle : : getAvailableVariants ( info . stylePath , variants ) ;
ui . historyComboBoxVariant - > clear ( ) ;
ui . historyComboBoxVariant - > setEnabled ( variants . size ( ) ! = 0 ) ;
ui . historyComboBoxVariant - > addItems ( variants ) ;
/* try to find "Standard" */
int index = ui . historyComboBoxVariant - > findText ( VARIANT_STANDARD ) ;
if ( index ! = - 1 ) {
ui . historyComboBoxVariant - > setCurrentIndex ( index ) ;
} else {
ui . historyComboBoxVariant - > setCurrentIndex ( 0 ) ;
}
2010-09-07 11:49:31 -04:00
} else {
ui . historyAuthor - > clear ( ) ;
ui . historyDescription - > clear ( ) ;
2010-09-07 19:19:27 -04:00
ui . historyComboBoxVariant - > clear ( ) ;
ui . historyComboBoxVariant - > setDisabled ( true ) ;
2010-09-07 11:49:31 -04:00
}
2010-09-07 19:19:27 -04:00
fillPreview ( ui . historyList , ui . historyComboBoxVariant , ui . historyPreview ) ;
}
2011-08-12 10:06:29 -04:00
void ChatPage : : on_publicComboBoxVariant_currentIndexChanged ( int /*index*/ )
2010-09-07 19:19:27 -04:00
{
fillPreview ( ui . publicList , ui . publicComboBoxVariant , ui . publicPreview ) ;
}
2011-08-12 10:06:29 -04:00
void ChatPage : : on_privateComboBoxVariant_currentIndexChanged ( int /*index*/ )
2010-09-07 19:19:27 -04:00
{
fillPreview ( ui . privateList , ui . privateComboBoxVariant , ui . privatePreview ) ;
}
2011-08-12 10:06:29 -04:00
void ChatPage : : on_historyComboBoxVariant_currentIndexChanged ( int /*index*/ )
2010-09-07 19:19:27 -04:00
{
fillPreview ( ui . historyList , ui . historyComboBoxVariant , ui . historyPreview ) ;
2010-09-07 11:49:31 -04:00
}