• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kopete/kopete

chatwindowconfig.cpp

Go to the documentation of this file.
00001 /*
00002     chatwindowconfig.cpp  -  Kopete Look Feel Config
00003 
00004     Copyright (c) 2005-2006 by Michaël Larouche       <larouche@kde.org>
00005     Copyright (c) 2005-2006 by Olivier Goffart         <ogoffart at kde.org>
00006     Copyright (c) 2007      by Gustavo Pichorim Boiko  <gustavo.boiko@kdemail.net>
00007 
00008     Kopete    (c) 2005-2007 by the Kopete developers  <kopete-devel@kde.org>
00009 
00010     *************************************************************************
00011     *                                                                       *
00012     * This program is free software; you can redistribute it and/or modify  *
00013     * it under the terms of the GNU General Public License as published by  *
00014     * the Free Software Foundation; either version 2 of the License, or     *
00015     * (at your option) any later version.                                   *
00016     *                                                                       *
00017     *************************************************************************
00018 */
00019 
00020 #include "chatwindowconfig.h"
00021 #include "emoticonthemedelegate.h"
00022 #include "emoticonthemeitem.h"
00023 
00024 #include <QCheckBox>
00025 #include <QDir>
00026 #include <QLayout>
00027 #include <QSpinBox>
00028 #include <QSlider>
00029 #include <QLabel>
00030 #include <QPixmap>
00031 #include <QVBoxLayout>
00032 
00033 #include <kdeversion.h>
00034 #include <kinputdialog.h>
00035 
00036 #include <kcolorcombo.h>
00037 #include <kcolorbutton.h>
00038 #include <kdebug.h>
00039 #include <kfontrequester.h>
00040 #include <kpluginfactory.h>
00041 #include <kio/netaccess.h>
00042 #include <khtmlview.h>
00043 #include <klineedit.h>
00044 #include <klocale.h>
00045 #include <kmessagebox.h>
00046 #include <kpushbutton.h>
00047 #include <kstandarddirs.h>
00048 #include <kurlrequesterdialog.h>
00049 #include <krun.h>
00050 #include <kfiledialog.h>
00051 #include <kurl.h>
00052 #include <kemoticons.h>
00053 #include <KCMultiDialog>
00054 
00055 // KNewStuff
00056 #include <knewstuff2/engine.h>
00057 
00058 // For Kopete Chat Window Style configuration and preview.
00059 #include <kopetechatwindowstylemanager.h>
00060 #include <kopetechatwindowstyle.h>
00061 #include <chatmessagepart.h>
00062 
00063 
00064 // Things we fake to get the message preview to work
00065 #include <kopeteprotocol.h>
00066 #include <kopetemetacontact.h>
00067 #include <kopeteaccount.h>
00068 #include <kopeteidentity.h>
00069 #include <kopetecontact.h>
00070 #include <kopetemessage.h>
00071 #include <kopetechatsession.h>
00072 #include <kopetechatsessionmanager.h>
00073 #include <kopetestatusmessage.h>
00074 #include <kopeteappearancesettings.h>
00075 
00076 #include "kopeteemoticons.h"
00077 
00078 #include "kopeteglobal.h"
00079 
00080 #include "kopetechatwindowsettings.h"
00081 
00082 K_PLUGIN_FACTORY( KopeteChatWindowConfigFactory,
00083         registerPlugin<ChatWindowConfig>(); )
00084 K_EXPORT_PLUGIN( KopeteChatWindowConfigFactory("kcm_kopete_chatwindowconfig") )
00085 
00086 // Reimplement Kopete::Contact and its abstract method
00087 // This is for style preview.
00088 class FakeContact : public Kopete::Contact
00089 {
00090 public:
00091     FakeContact (Kopete::Account *account, const QString &id, Kopete::MetaContact *mc ) : Kopete::Contact( account, id, mc ) {}
00092     virtual Kopete::ChatSession *manager(Kopete::Contact::CanCreateFlags /*c*/) { return 0L; }
00093     virtual void slotUserInfo() {}
00094 };
00095 
00096 // This is for style preview.
00097 class FakeProtocol : public Kopete::Protocol
00098 {
00099 public:
00100 FakeProtocol( const KComponentData &instance, QObject *parent ) : Kopete::Protocol(instance, parent){}
00101 Kopete::Account* createNewAccount( const QString &/*accountId*/ ){return 0L;}
00102 AddContactPage* createAddContactWidget( QWidget */*parent*/, Kopete::Account */*account*/){return 0L;}
00103 KopeteEditAccountWidget* createEditAccountWidget( Kopete::Account */*account*/, QWidget */*parent */){return 0L;}
00104 };
00105 
00106 // This is for style preview.
00107 class FakeIdentity : public Kopete::Identity
00108 {
00109     public:
00110         FakeIdentity() : Kopete::Identity("Preview Identity") {};
00111 };
00112 
00113 // This is for style preview.
00114 class FakeAccount : public Kopete::Account
00115 {
00116 public:
00117     FakeAccount(Kopete::Protocol *parent, const QString &accountID) : Kopete::Account(parent, accountID)
00118     {
00119         m_identity = new FakeIdentity();
00120         setIdentity(m_identity);
00121     }
00122 
00123     void setMyself(Kopete::Contact *myself)
00124     {
00125         Kopete::Account::setMyself(myself);
00126     }
00127 
00128     ~FakeAccount()
00129     {
00130         delete m_identity;
00131     }
00132 
00133 bool createContact( const QString &/*contactId*/, Kopete::MetaContact */*parentContact*/ ){return true;}
00134 void connect( const Kopete::OnlineStatus& /*initialStatus*/){}
00135 void disconnect(){}
00136 void setOnlineStatus( const Kopete::OnlineStatus& /*status*/ , const Kopete::StatusMessage &/*reason*/){}
00137 void setStatusMessage(const Kopete::StatusMessage& /*statusMessage*/){}
00138 
00139 private:
00140     FakeIdentity *m_identity;
00141 };
00142 
00143 ChatWindowConfig::ChatWindowConfig(QWidget *parent, const QVariantList &args )
00144     : KCModule( KopeteChatWindowConfigFactory::componentData(), parent, args ),
00145         m_currentStyle (0L), m_loading(false),
00146         m_previewProtocol(0L), m_previewAccount(0L), m_myselfMetaContact(0L),
00147         m_jackMetaContact(0L), m_myself(0L), m_jack(0L)
00148 {
00149     KConfigGroup config(KGlobal::config(), "ChatWindowSettings");
00150 
00151     QVBoxLayout *layout = new QVBoxLayout(this);
00152     // since KSetting::Dialog has margins here, we don't need our own.
00153     layout->setContentsMargins( 0, 0, 0, 0);
00154     m_tab = new QTabWidget(this);
00155     layout->addWidget(m_tab);
00156 
00157 //--------- style tab ---------------------
00158     QWidget *styleWidget = new QWidget(m_tab);
00159     m_styleUi.setupUi(styleWidget);
00160     m_tab->addTab(styleWidget, i18n("&Style"));
00161     addConfig( KopeteChatWindowSettings::self(), styleWidget );
00162 
00163     connect(m_styleUi.styleList, SIGNAL(currentTextChanged(const QString &)),
00164         this, SLOT(slotChatStyleSelected(const QString &)));
00165     connect(m_styleUi.variantList, SIGNAL(activated(const QString&)),
00166         this, SLOT(slotChatStyleVariantSelected(const QString &)));
00167     connect(m_styleUi.deleteButton, SIGNAL(clicked()),
00168         this, SLOT(slotDeleteChatStyle()));
00169     connect(m_styleUi.installButton, SIGNAL(clicked()),
00170         this, SLOT(slotInstallChatStyle()));
00171     connect(m_styleUi.btnGetStyles, SIGNAL(clicked()),
00172         this, SLOT(slotGetChatStyles()));
00173 
00174     m_styleUi.deleteButton->setIcon(KIcon("edit-delete"));
00175     m_styleUi.installButton->setIcon(KIcon("document-import"));
00176     m_styleUi.btnGetStyles->setIcon(KIcon("get-hot-new-stuff"));
00177 
00178     // Show the available styles when the Manager has finish to load the styles.
00179     connect(ChatWindowStyleManager::self(), SIGNAL(loadStylesFinished()), this, SLOT(slotLoadChatStyles()));
00180 
00181     // Create the fake Chat Session
00182     createPreviewChatSession();
00183     m_preview = new ChatMessagePart(m_previewChatSession, m_styleUi.htmlFrame);
00184     m_preview->setJScriptEnabled(false);
00185     m_preview->setJavaEnabled(false);
00186     m_preview->setPluginsEnabled(false);
00187     m_preview->setMetaRefreshEnabled(false);
00188     KHTMLView *htmlWidget = m_preview->view();
00189     htmlWidget->setMarginWidth(4);
00190     htmlWidget->setMarginHeight(4);
00191     htmlWidget->setFocusPolicy(Qt::NoFocus);
00192     htmlWidget->setSizePolicy(
00193         QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
00194     layout = new QVBoxLayout(m_styleUi.htmlFrame);
00195     layout->setMargin(0);
00196     layout->addWidget(htmlWidget);
00197     m_styleUi.htmlFrame->setLayout(layout);
00198     // Add the preview message to the ChatMessagePart
00199     createPreviewMessages();
00200 
00201 
00202 //--------- emoticons tab ---------------------
00203     QWidget *emoticonsWidget = new QWidget(m_tab);
00204     m_emoticonsUi.setupUi(emoticonsWidget);
00205     m_tab->addTab(emoticonsWidget, i18n("&Emoticons"));
00206 
00207     m_emoticonsUi.icon_theme_list->setItemDelegate(new EmoticonThemeDelegate(this));
00208     addConfig( Kopete::AppearanceSettings::self(), emoticonsWidget );
00209 
00210     connect(m_emoticonsUi.icon_theme_list, SIGNAL(itemSelectionChanged()),
00211         this, SLOT(emitChanged()));
00212 
00213     connect(m_emoticonsUi.btnManageThemes, SIGNAL(clicked()),
00214         this, SLOT(slotManageEmoticonThemes()));
00215 
00216 //--------- colors tab --------------------------
00217     QWidget *colorsWidget = new QWidget(m_tab);
00218     m_colorsUi.setupUi(colorsWidget);
00219     m_tab->addTab(colorsWidget, i18n("Colors && Fonts"));
00220     addConfig( Kopete::AppearanceSettings::self(), colorsWidget );
00221 
00222     load();
00223 }
00224 
00225 ChatWindowConfig::~ChatWindowConfig()
00226 {
00227     if (m_previewChatSession)
00228     {
00229         Kopete::ChatSessionManager::self()->removeSession(m_previewChatSession);
00230     }
00231 
00232     // Deleting the account will delete jack and myself
00233     delete m_previewAccount;
00234 
00235     delete m_myselfMetaContact;
00236     delete m_jackMetaContact;
00237 
00238     delete m_previewProtocol;
00239 }
00240 
00241 
00242 void ChatWindowConfig::save()
00243 {
00244     KCModule::save();
00245 //  kDebug(14000) << "called.";
00246 
00247     KopeteChatWindowSettings *settings = KopeteChatWindowSettings::self();
00248 
00249     // Get the styleName
00250     if(m_currentStyle)
00251     {
00252         kDebug(14000) << m_currentStyle->getStyleName();
00253         settings->setStyleName( m_currentStyle->getStyleName() );
00254     }
00255     // Get and save the styleVariant
00256     if( !m_currentVariantMap.empty() )
00257     {
00258         kDebug(14000) << m_currentVariantMap[ m_styleUi.variantList->currentText()];
00259         settings->setStyleVariant( m_currentVariantMap[m_styleUi.variantList->currentText()] );
00260     }
00261 
00262     Kopete::AppearanceSettings *appearanceSettings = Kopete::AppearanceSettings::self();
00263     QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem();
00264     
00265     if (item)
00266         KEmoticons::setTheme( item->text() );
00267 
00268     // Ugly hacks, this will emit the kcfg signals
00269     appearanceSettings->setChatTextColor(m_colorsUi.kcfg_chatTextColor->color());
00270     appearanceSettings->setUseEmoticons(m_emoticonsUi.kcfg_useEmoticons->isChecked());
00271     settings->setHighlightForegroundColor(m_colorsUi.kcfg_highlightForegroundColor->color());
00272     settings->setChatBgOverride(m_colorsUi.kcfg_chatBgOverride->isChecked());
00273 
00274     appearanceSettings->writeConfig();
00275     settings->writeConfig();
00276 
00277     load();
00278 }
00279 
00280 void ChatWindowConfig::load()
00281 {
00282     KCModule::load();
00283 
00284     //we will change the state of somme controls, which will call some signals.
00285     //so to don't refresh everything several times, we memorize we are loading.
00286     m_loading=true;
00287 
00288     // Look for available chat window styles.
00289     slotLoadChatStyles();
00290 
00291     // Look for available emoticons themes
00292     updateEmoticonList();
00293 
00294     m_loading=false;
00295     slotUpdateChatPreview();
00296 }
00297 
00298 void ChatWindowConfig::slotLoadChatStyles()
00299 {
00300     m_styleUi.styleList->clear();
00301 
00302     QStringList availableStyles;
00303     availableStyles = ChatWindowStyleManager::self()->getAvailableStyles();
00304     if( availableStyles.empty() )
00305         kDebug(14000) << "Warning, available styles is empty !";
00306 
00307     foreach( const QString& styleName, availableStyles )
00308     {
00309         // Insert style name into the listbox
00310         m_styleUi.styleList->insertItem( 0, styleName );
00311     }
00312 
00313     m_styleUi.styleList->setSortingEnabled( true );
00314 
00315     QString currentStyle = KopeteChatWindowSettings::self()->styleName();
00316     QList<QListWidgetItem *> items = m_styleUi.styleList->findItems( currentStyle, Qt::MatchFixedString | Qt::MatchCaseSensitive );
00317     if( items.count() > 0 )
00318     {
00319         kDebug(14000) << "Restoring saved style: " << currentStyle;
00320 
00321         m_styleUi.styleList->setCurrentItem( items[0] );
00322         m_styleUi.styleList->scrollToItem( items[0] );
00323     }
00324 }
00325 
00326 
00327 void ChatWindowConfig::slotChatStyleSelected(const QString &styleName)
00328 {
00329     if (styleName.isEmpty())
00330         return;
00331     // Retrieve variant list.
00332     m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
00333 
00334     if(m_currentStyle)
00335     {
00336         m_currentVariantMap = m_currentStyle->getVariants();
00337         kDebug(14000) << "Loading style: " << m_currentStyle->getStyleName();
00338 
00339         // Update the variant list based on current style.
00340         m_styleUi.variantList->clear();
00341 
00342         // Add the no variant item to the list
00343         // TODO: Use default name variant from Info.plist
00344         // TODO: Select default variant from Info.plist
00345         m_styleUi.variantList->addItem( i18n("(No Variant)") );
00346 
00347         ChatWindowStyle::StyleVariants::ConstIterator it, itEnd = m_currentVariantMap.constEnd();
00348         int currentIndex = 0;
00349         for(it = m_currentVariantMap.constBegin(); it != itEnd; ++it)
00350         {
00351             // Insert variant name into the combobox.
00352             m_styleUi.variantList->addItem( it.key() );
00353 
00354             if( it.value() == KopeteChatWindowSettings::self()->styleVariant() )
00355                 m_styleUi.variantList->setCurrentIndex(currentIndex+1);
00356 
00357             currentIndex++;
00358         }
00359 
00360         // Update the preview
00361         slotUpdateChatPreview();
00362         // Get the first variant to preview
00363         // Check if the current style has variants.
00364         if( !m_currentVariantMap.empty() ) {
00365             m_preview->setStyleVariant(m_currentVariantMap[0]);
00366             m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( QString() ) );
00367         }
00368 
00369         emitChanged();
00370     }
00371 }
00372 
00373 void ChatWindowConfig::slotChatStyleVariantSelected(const QString &variantName)
00374 {
00375 //  kDebug(14000) << variantName;
00376 //  kDebug(14000) << m_currentVariantMap[variantName];
00377 
00378     // enable the 'Use compact' checkbox depending on whether the selected variant exists in compact
00379     // form
00380     QString styleName = m_styleUi.styleList->currentItem()->text();
00381     m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
00382     if ( m_styleUi.variantList->currentIndex() == 0 ) {
00383         m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( "" ) );
00384     }
00385     else {
00386         m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( variantName ) );
00387     }
00388     // Update the preview
00389     m_preview->setStyleVariant(m_currentVariantMap[variantName]);
00390     emitChanged();
00391 }
00392 
00393 void ChatWindowConfig::slotInstallChatStyle()
00394 {
00395     KUrl styleUrl = KFileDialog::getOpenUrl( KUrl(), QString::fromUtf8("application/zip application/x-compressed-tar application/x-bzip-compressed-tar"), this, i18n("Choose a Chat Window Style to install") );
00396 
00397     if ( styleUrl.isEmpty() ) // dialog got canceled
00398         return;
00399 
00400     int styleInstallReturn = installChatStyle( styleUrl );
00401 
00402     switch(styleInstallReturn)
00403     {
00404         case ChatWindowStyleManager::StyleCannotOpen:
00405         {
00406             KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("The specified archive cannot be opened.\nMake sure that the archive is a valid ZIP or TAR archive."), i18n("Cannot open archive") );
00407             break;
00408         }
00409         case ChatWindowStyleManager::StyleNoDirectoryValid:
00410         {
00411             KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("Could not find a suitable place to install the Chat Window Style."), i18n("Cannot find styles directory") );
00412             break;
00413         }
00414         case ChatWindowStyleManager::StyleNotValid:
00415             KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("The specified archive does not contain a valid Chat Window Style."), i18n("Invalid Style") );
00416             break;
00417         case ChatWindowStyleManager::StyleInstallOk:
00418         {
00419             KMessageBox::queuedMessageBox( this, KMessageBox::Information, i18n("The Chat Window Style was successfully installed."), i18n("Install successful") );
00420             break;
00421         }
00422         case ChatWindowStyleManager::StyleUnknow:
00423         default:
00424         {
00425             KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("An unknown error occurred while trying to install the Chat Window Style."), i18n("Unknown error") );
00426             break;
00427         }
00428     }
00429 }
00430 
00431 int ChatWindowConfig::installChatStyle(const KUrl &styleToInstall)
00432 {
00433     int styleInstallReturn = ChatWindowStyleManager::StyleCannotOpen;
00434 
00435     if( !styleToInstall.isEmpty() )
00436     {
00437         QString stylePath;
00438         if( KIO::NetAccess::download( styleToInstall, stylePath, this ) )
00439         {
00440             styleInstallReturn = ChatWindowStyleManager::self()->installStyle( stylePath );
00441 
00442             // removeTempFile check if the file is a temp file, so it's ok for local files.
00443             KIO::NetAccess::removeTempFile( stylePath );
00444         }
00445     }
00446 
00447     return styleInstallReturn;
00448 }
00449 
00450 void ChatWindowConfig::slotDeleteChatStyle()
00451 {
00452     if (!m_styleUi.styleList->currentItem())
00453     {
00454         return; // nothing selected
00455     }
00456 
00457     QString styleName = m_styleUi.styleList->currentItem()->text();
00458     if( ChatWindowStyleManager::self()->removeStyle(styleName) )
00459     {
00460         KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18nc("@info", "The Chat Window Style <resource>%1</resource> was successfully deleted.", styleName));
00461         emitChanged();
00462     }
00463     else
00464     {
00465         KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, i18nc("@info", "An error occurred while trying to delete the <resource>%1</resource> Chat Window Style. Your account might not have permission to remove it.", styleName));
00466     }
00467 }
00468 
00469 void ChatWindowConfig::slotGetChatStyles()
00470 {
00471     KConfigGroup configGrp(KGlobal::config(), "KNewStuff2");
00472     configGrp.writeEntry("ProvidersUrl", "http://download.kde.org/khotnewstuff/kopetestyles12-providers.xml");
00473     configGrp.writeEntry("TargetDir", "kopete_chatstyles");
00474     configGrp.sync();
00475     
00476     KNS::Engine *engine = new KNS::Engine();
00477     engine->init(configGrp.config()->name());
00478     
00479     // FIXME: Upon closing the Settings KCMultiDialog all KCMs are deleted and when reopening
00480     // the settings dialog there is no active valid KComponentData, which KNS2 relies on.
00481     // Forcing an active one below works around bug 163382, but the problem is somewhere else.
00482     KGlobal::setActiveComponent(KopeteChatWindowConfigFactory::componentData());
00483 
00484     KNS::Entry::List entries = engine->downloadDialogModal(this);
00485 
00486     if ( entries.size() > 0 )
00487     {
00488         int correctlyInstalled(0);
00489         foreach( KNS::Entry* entry, entries )
00490         {
00491             if ( entry->status() == KNS::Entry::Installed && entry->installedFiles().size() > 0 )
00492             {
00493                 KUrl styleFile( entry->installedFiles().at(0) );
00494                 int result = installChatStyle( styleFile );
00495 
00496                 QString packageName(entry->name().representation());
00497                 QString errorTitle = i18nc("@title:window", "Chat Window Style <resource>%1</resource> installation", packageName);
00498                 switch(result)
00499                 {
00500                     case ChatWindowStyleManager::StyleCannotOpen:
00501                     {
00502                         KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "The specified archive <filename>%1</filename> cannot be opened.\nMake sure that the archive is a valid ZIP or TAR archive.", styleFile.pathOrUrl()), errorTitle);
00503                         break;
00504                     }
00505                     case ChatWindowStyleManager::StyleNoDirectoryValid:
00506                     {
00507                         KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "Could not find a suitable place to install the Chat Window Style <resource>%1</resource>.", packageName), errorTitle );
00508                         break;
00509                     }
00510                     case ChatWindowStyleManager::StyleNotValid:
00511                         KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "The specified archive <filename>%1</filename> does not contain a valid Chat Window Style.", styleFile.pathOrUrl()), errorTitle );
00512                         break;
00513                     case ChatWindowStyleManager::StyleInstallOk:
00514                     {
00515                         ++correctlyInstalled;
00516                         break;
00517                     }
00518                     case ChatWindowStyleManager::StyleUnknow:
00519                     default:
00520                     {
00521                         KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "An unknown error occurred while trying to install the Chat Window Style <resource>%1</resource>.", packageName), errorTitle );
00522                         break;
00523                     }
00524                 }
00525             }
00526         }
00527 
00528         if ( correctlyInstalled > 0)
00529         {
00530             KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18np("One Chat Window Style package has been installed.", "%1 Chat Window Style packages have been installed.", correctlyInstalled));
00531         }
00532     }
00533 
00534     delete engine;
00535 }
00536 
00537 void ChatWindowConfig::createPreviewChatSession()
00538 {
00539     m_previewProtocol = new FakeProtocol( KComponentData(QByteArray("kopete-preview-chatwindowstyle")), 0 ); m_previewProtocol->setObjectName( QLatin1String("kopete-preview-chatwindowstyle") );
00540     m_previewAccount = new FakeAccount(m_previewProtocol, QString("previewaccount"));
00541 
00542     // Create fake meta/contacts
00543     m_myselfMetaContact = new Kopete::MetaContact();
00544     m_myselfMetaContact->setTemporary();
00545     m_myselfMetaContact->setDisplayName(i18n("Myself"));
00546     m_myselfMetaContact->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
00547 
00548     m_myself = new FakeContact(m_previewAccount, i18nc("This is the myself preview contact id", "myself@preview"), m_myselfMetaContact);
00549     m_myself->setNickName(i18nc("This is the myself preview contact nickname", "Myself"));
00550 
00551     m_jackMetaContact = new Kopete::MetaContact();
00552     m_jackMetaContact->setTemporary();
00553     m_jackMetaContact->setDisplayName(i18n("Jack"));
00554     m_jackMetaContact->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
00555 
00556     m_jack = new FakeContact(m_previewAccount, i18nc("This is the other preview contact id", "jack@preview"), m_jackMetaContact);
00557     m_jack->setNickName(i18nc("This is the other preview contact nickname", "Jack"));
00558 
00559     m_previewAccount->setMyself(m_myself);
00560 
00561     Kopete::ContactPtrList contactList;
00562     contactList.append(m_jack);
00563     // Create fakeChatSession
00564     m_previewChatSession = Kopete::ChatSessionManager::self()->create(m_myself, contactList, m_previewProtocol);
00565     m_previewChatSession->setDisplayName(i18nc("preview of a chat session", "Preview Session"));
00566 }
00567 
00568 void ChatWindowConfig::createPreviewMessages()
00569 {
00570     Kopete::Message msgIn( m_jack,m_myself );
00571     msgIn.setPlainBody( i18n( "Hello, this is an incoming message :-)" ) );
00572     msgIn.setDirection( Kopete::Message::Inbound );
00573 
00574     Kopete::Message msgIn2( m_jack, m_myself );
00575     msgIn2.setPlainBody( i18n( "Hello, this is an incoming consecutive message." ) );
00576     msgIn2.setDirection( Kopete::Message::Inbound );
00577 
00578     Kopete::Message msgOut( m_myself, m_jack );
00579     msgOut.setPlainBody( i18n( "Ok, this is an outgoing message" ) );
00580     msgOut.setDirection( Kopete::Message::Outbound );
00581 
00582     Kopete::Message msgOut2( m_myself, m_jack );
00583     msgOut2.setPlainBody( i18n( "Ok, an outgoing consecutive message." ) );
00584     msgOut2.setDirection( Kopete::Message::Outbound );
00585 
00586     Kopete::Message msgOut3( m_myself, m_jack );
00587     msgOut3.setPlainBody( i18n( "Message that is being sent." ) );
00588     msgOut3.setDirection( Kopete::Message::Outbound );
00589     msgOut3.setState( Kopete::Message::StateSending );
00590 
00591     Kopete::Message msgOut4( m_myself, m_jack );
00592     msgOut4.setPlainBody( i18n( "Delivered message." ) );
00593     msgOut4.setDirection( Kopete::Message::Outbound );
00594     msgOut4.setState( Kopete::Message::StateSent );
00595 
00596     Kopete::Message msgOut5( m_myself, m_jack );
00597     msgOut5.setPlainBody( i18n( "Message that can't be delivered." ) );
00598     msgOut5.setDirection( Kopete::Message::Outbound );
00599     msgOut5.setState( Kopete::Message::StateError );
00600 
00601     Kopete::Message msgCol( m_jack, m_myself );
00602     msgCol.setPlainBody( i18n("Here is an incoming colored message.") );
00603     msgCol.setDirection( Kopete::Message::Inbound );
00604     msgCol.setForegroundColor( QColor( "DodgerBlue" ) );
00605     msgCol.setBackgroundColor( QColor( "LightSteelBlue" ) );
00606 
00607     Kopete::Message msgInt( m_jack, m_myself );
00608     msgInt.setPlainBody( i18n( "This is an internal message" ) );
00609     msgInt.setDirection( Kopete::Message::Internal );
00610 
00611     Kopete::Message msgAct( m_jack, m_myself );
00612     msgAct.setPlainBody( i18n( "performed an action" ) );
00613     msgAct.setType( Kopete::Message::TypeAction );
00614     msgAct.setDirection( Kopete::Message::Inbound );
00615 
00616     Kopete::Message msgHigh( m_jack, m_myself );
00617     msgHigh.setPlainBody( i18n( "This is a highlighted message" ) );
00618     msgHigh.setDirection( Kopete::Message::Inbound );
00619     msgHigh.setImportance( Kopete::Message::Highlight );
00620 
00621     Kopete::Message msgFTRequest( m_jack, m_myself );
00622     msgFTRequest.setPlainBody( i18n( "Hello, this is an incoming file transfer request" ) );
00623     msgFTRequest.setDirection( Kopete::Message::Inbound );
00624     msgFTRequest.setType( Kopete::Message::TypeFileTransferRequest );
00625     msgFTRequest.setFileName( "data.pdf" );
00626     msgFTRequest.setFileSize( 10000000 );
00627 
00628     Kopete::Message msgFTRequestDisabled( m_jack, m_myself );
00629     msgFTRequestDisabled.setPlainBody( i18n( "Hello, this is a disabled incoming file transfer request" ) );
00630     msgFTRequestDisabled.setDirection( Kopete::Message::Inbound );
00631     msgFTRequestDisabled.setType( Kopete::Message::TypeFileTransferRequest );
00632     msgFTRequestDisabled.setFileName( "data.pdf" );
00633     msgFTRequestDisabled.setFileSize( 10000000 );
00634     msgFTRequestDisabled.setFileTransferDisabled( true );
00635 
00636     // This is a UTF-8 string btw.
00637     Kopete::Message msgRightToLeft( m_myself, m_jack );
00638     msgRightToLeft.setPlainBody( i18nc("This special UTF-8 string is to test if the style supports Right-to-Left language display.", "הודעות טקסט") );
00639     msgRightToLeft.setDirection( Kopete::Message::Outbound );
00640 
00641     Kopete::Message msgBye ( m_myself, m_jack );
00642     msgBye.setPlainBody( i18n("Bye") );
00643     msgBye.setDirection( Kopete::Message::Outbound );
00644 
00645     // Add the messages to ChatMessagePart
00646     m_preview->appendMessage(msgIn);
00647     m_preview->appendMessage(msgIn2);
00648     m_preview->appendMessage(msgOut);
00649     m_preview->appendMessage(msgOut2);
00650     m_preview->appendMessage(msgOut3);
00651     m_preview->appendMessage(msgOut4);
00652     m_preview->appendMessage(msgOut5);
00653     m_preview->appendMessage(msgCol);
00654     m_preview->appendMessage(msgInt);
00655     m_preview->appendMessage(msgAct);
00656     m_preview->appendMessage(msgHigh);
00657     m_preview->appendMessage(msgFTRequest);
00658     m_preview->appendMessage(msgFTRequestDisabled);
00659     m_preview->appendMessage(msgRightToLeft);
00660     m_preview->appendMessage(msgBye);
00661 }
00662 
00663 void ChatWindowConfig::slotUpdateChatPreview()
00664 {
00665     if(m_loading || !m_currentStyle)
00666         return;
00667 
00668     // Update the preview
00669     m_preview->setStyle(m_currentStyle);
00670 
00671     emitChanged();
00672 }
00673 
00674 
00675 void ChatWindowConfig::updateEmoticonList()
00676 {
00677     KStandardDirs dir;
00678 
00679     m_emoticonsUi.icon_theme_list->clear(); // Wipe out old list
00680     // Get a list of directories in our icon theme dir
00681     QStringList themeDirs = KGlobal::dirs()->findDirs("emoticons", "");
00682     // loop adding themes from all dirs into theme-list
00683     for( int x = 0;x < themeDirs.count();x++)
00684     {
00685         QDir themeQDir(themeDirs[x]);
00686         themeQDir.setFilter( QDir::Dirs ); // only scan for subdirs
00687         themeQDir.setSorting( QDir::Name ); // I guess name is as good as any
00688         for(unsigned int y = 0; y < themeQDir.count(); y++)
00689         {
00690             QStringList themes = themeQDir.entryList(QDir::Dirs, QDir::Name);
00691 
00692             // We don't care for '.' and '..'
00693             if ( themeQDir[y] != "." && themeQDir[y] != ".." )
00694             {
00695                 // Add ourselves to the list, using our directory name  FIXME:  use the first emoticon of the theme.
00696                 QListWidgetItem *item = new EmoticonThemeItem(themeQDir[y]);
00697                 m_emoticonsUi.icon_theme_list->addItem(item);
00698             }
00699         }
00700     }
00701 
00702     // Where is that theme in our big-list-o-themes?
00703 
00704     QList<QListWidgetItem*> items = m_emoticonsUi.icon_theme_list->findItems( KEmoticons::currentThemeName(), Qt::MatchExactly );
00705 
00706     if (items.count()) // found it... make it the currently selected theme
00707         m_emoticonsUi.icon_theme_list->setCurrentItem( items.first() );
00708     else // Er, it's not there... select the current item
00709         m_emoticonsUi.icon_theme_list->setCurrentItem( 0 );
00710 }
00711 
00712 
00713 void ChatWindowConfig::slotManageEmoticonThemes()
00714 {
00715     // FIXME: Upon closing the Settings KCMultiDialog all KCMs are deleted and when reopening
00716     // the settings dialog there is no active valid KComponentData, which KNS2 relies on.
00717     // Forcing an active one below works around bug 165919, but the problem is somewhere else.
00718     KGlobal::setActiveComponent(KopeteChatWindowConfigFactory::componentData());
00719 
00720     KCMultiDialog *kcm = new KCMultiDialog( this );
00721     kcm->setCaption( i18n( "Configure Emoticon Themes" ) );
00722     kcm->addModule( "emoticons" );
00723     kcm->exec();
00724     updateEmoticonList();
00725 }
00726 
00727 
00728 void ChatWindowConfig::emitChanged()
00729 {
00730     emit changed( true );
00731 }
00732 
00733 #include "chatwindowconfig.moc"

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal