• Skip to content
  • Skip to link menu
KDE 4.0 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 <kurl.h> // KNewStuff
00049 #include <kurlrequesterdialog.h>
00050 #include <krun.h>
00051 #include <kfiledialog.h>
00052 
00053 #ifdef __GNUC__
00054 #warning "Port KNS changes!"
00055 #endif
00056 #if 0
00057 #include <knewstuff/downloaddialog.h> // knewstuff emoticon and chatwindow fetching
00058 #include <knewstuff/engine.h>         // "
00059 #include <knewstuff/entry.h>          // "
00060 #include <knewstuff/knewstuff.h>      // "
00061 #include <knewstuff/provider.h>       // "
00062 #endif
00063 
00064 // For Kopete Chat Window Style configuration and preview.
00065 #include <kopetechatwindowstylemanager.h>
00066 #include <kopetechatwindowstyle.h>
00067 #include <chatmessagepart.h>
00068 
00069 
00070 // Things we fake to get the message preview to work
00071 #include <kopeteprotocol.h>
00072 #include <kopetemetacontact.h>
00073 #include <kopeteaccount.h>
00074 #include <kopeteidentity.h>
00075 #include <kopetecontact.h>
00076 #include <kopetemessage.h>
00077 #include <kopetechatsession.h>
00078 #include <kopetechatsessionmanager.h>
00079 #include <kopetestatusmessage.h>
00080 #include <kopeteappearancesettings.h>
00081 
00082 #include "kopeteemoticons.h"
00083 
00084 #include "kopeteglobal.h"
00085 
00086 #include "kopetechatwindowsettings.h"
00087 
00088 K_PLUGIN_FACTORY( KopeteChatWindowConfigFactory,
00089         registerPlugin<ChatWindowConfig>(); )
00090 K_EXPORT_PLUGIN( KopeteChatWindowConfigFactory("kcm_kopete_chatwindowconfig") )
00091 
00092 // Reimplement Kopete::Contact and its abstract method
00093 // This is for style preview.
00094 class FakeContact : public Kopete::Contact
00095 {
00096 public:
00097     FakeContact (Kopete::Account *account, const QString &id, Kopete::MetaContact *mc ) : Kopete::Contact( account, id, mc ) {}
00098     virtual Kopete::ChatSession *manager(Kopete::Contact::CanCreateFlags /*c*/) { return 0L; }
00099     virtual void slotUserInfo() {}
00100 };
00101 
00102 // This is for style preview.
00103 class FakeProtocol : public Kopete::Protocol
00104 {
00105 public:
00106 FakeProtocol( const KComponentData &instance, QObject *parent ) : Kopete::Protocol(instance, parent){}
00107 Kopete::Account* createNewAccount( const QString &/*accountId*/ ){return 0L;}
00108 AddContactPage* createAddContactWidget( QWidget */*parent*/, Kopete::Account */*account*/){return 0L;}
00109 KopeteEditAccountWidget* createEditAccountWidget( Kopete::Account */*account*/, QWidget */*parent */){return 0L;}
00110 };
00111 
00112 // This is for style preview.
00113 class FakeIdentity : public Kopete::Identity
00114 {
00115     public:
00116         FakeIdentity() : Kopete::Identity("Preview Identity") {};
00117 };
00118 
00119 // This is for style preview.
00120 class FakeAccount : public Kopete::Account
00121 {
00122 public:
00123     FakeAccount(Kopete::Protocol *parent, const QString &accountID) : Kopete::Account(parent, accountID)
00124     {
00125         m_identity = new FakeIdentity();
00126         setIdentity(m_identity);
00127     }
00128 
00129     void setMyself(Kopete::Contact *myself)
00130     {
00131         Kopete::Account::setMyself(myself);
00132     }
00133 
00134     ~FakeAccount()
00135     {
00136         delete m_identity;
00137     }
00138 
00139 bool createContact( const QString &/*contactId*/, Kopete::MetaContact */*parentContact*/ ){return true;}
00140 void connect( const Kopete::OnlineStatus& /*initialStatus*/){}
00141 void disconnect(){}
00142 void setOnlineStatus( const Kopete::OnlineStatus& /*status*/ , const Kopete::StatusMessage &/*reason*/){}
00143 void setStatusMessage(const Kopete::StatusMessage& /*statusMessage*/){}
00144 
00145 private:
00146     FakeIdentity *m_identity;
00147 };
00148 
00149 
00150 #ifdef __GNUC__
00151 #warning "Port KNS changes!"
00152 #endif
00153 #if 0
00154 class KopeteStyleNewStuff : public KNewStuff
00155 {
00156 public:
00157     KopeteStyleNewStuff(const QString &type, QWidget *parentWidget = 0)
00158      : KNewStuff( type, parentWidget)
00159     {}
00160 
00161     bool createUploadFile(const QString &)
00162     {
00163         return false;
00164     }
00165 
00166     bool install(const QString &styleFilename)
00167     {
00168         int styleInstallReturn = 0;
00169         styleInstallReturn = ChatWindowStyleManager::self()->installStyle( styleFilename );
00170 
00171         switch(styleInstallReturn)
00172         {
00173             case ChatWindowStyleManager::StyleInstallOk:
00174             {
00175                 KMessageBox::queuedMessageBox( this->parentWidget(), KMessageBox::Information, i18n("The Chat Window style was successfully installed."), i18n("Install successful") );
00176                 return true;
00177             }
00178             case ChatWindowStyleManager::StyleCannotOpen:
00179             {
00180                 KMessageBox::queuedMessageBox( this->parentWidget(), KMessageBox::Error, i18n("The specified archive cannot be opened.\nMake sure that the archive is valid ZIP or TAR archive."), i18n("Cannot open archive") );
00181                 break;
00182             }
00183             case ChatWindowStyleManager::StyleNoDirectoryValid:
00184             {
00185                 KMessageBox::queuedMessageBox( this->parentWidget(), KMessageBox::Error, i18n("Could not find a suitable place to install the Chat Window style in user directory."), i18n("Cannot find styles directory") );
00186                 break;
00187             }
00188             case ChatWindowStyleManager::StyleNotValid:
00189             {
00190                 KMessageBox::queuedMessageBox( this->parentWidget(), KMessageBox::Error, i18n("The specified archive does not contain a valid Chat Window style."), i18n("Invalid Style") );
00191                 break;
00192             }
00193 
00194             case ChatWindowStyleManager::StyleUnknow:
00195             default:
00196             {
00197                 KMessageBox::queuedMessageBox( this->parentWidget(), KMessageBox::Error, i18n("An unknow error occurred while trying to install the Chat Window style."), i18n("Unknow error") );
00198                 break;
00199             }
00200         }
00201         return false;
00202     }
00203 };
00204 #endif
00205 
00206 ChatWindowConfig::ChatWindowConfig(QWidget *parent, const QVariantList &args )
00207     : KCModule( KopeteChatWindowConfigFactory::componentData(), parent, args ),
00208         m_currentStyle (0L), m_loading(false), m_styleChanged(false),
00209         m_previewProtocol(0L), m_previewAccount(0L), m_myselfMetaContact(0L),
00210         m_jackMetaContact(0L), m_myself(0L), m_jack(0L)
00211 {
00212     KConfigGroup config(KGlobal::config(), "ChatWindowSettings");
00213 
00214     QVBoxLayout *layout = new QVBoxLayout(this);
00215     // since KSetting::Dialog has margins here, we don't need our own.
00216     layout->setContentsMargins( 0, 0, 0, 0);
00217     m_tab = new QTabWidget(this);
00218     layout->addWidget(m_tab);
00219 
00220 //--------- style tab ---------------------
00221     QWidget *styleWidget = new QWidget(m_tab);
00222     m_styleUi.setupUi(styleWidget);
00223     m_tab->addTab(styleWidget, i18n("&Style"));
00224     addConfig( KopeteChatWindowSettings::self(), styleWidget );
00225 
00226     connect(m_styleUi.styleList, SIGNAL(selectionChanged(Q3ListBoxItem *)),
00227         this, SLOT(slotChatStyleSelected()));
00228     connect(m_styleUi.variantList, SIGNAL(activated(const QString&)),
00229         this, SLOT(slotChatStyleVariantSelected(const QString &)));
00230     connect(m_styleUi.deleteButton, SIGNAL(clicked()),
00231         this, SLOT(slotDeleteChatStyle()));
00232     connect(m_styleUi.installButton, SIGNAL(clicked()),
00233         this, SLOT(slotInstallChatStyle()));
00234     connect(m_styleUi.btnGetStyles, SIGNAL(clicked()),
00235         this, SLOT(slotGetChatStyles()));
00236 
00237     // Show the available styles when the Manager has finish to load the styles.
00238     connect(ChatWindowStyleManager::self(), SIGNAL(loadStylesFinished()), this, SLOT(slotLoadChatStyles()));
00239 
00240     // Create the fake Chat Session
00241     createPreviewChatSession();
00242     m_preview = new ChatMessagePart(m_previewChatSession, m_styleUi.htmlFrame);
00243     m_preview->setJScriptEnabled(false);
00244     m_preview->setJavaEnabled(false);
00245     m_preview->setPluginsEnabled(false);
00246     m_preview->setMetaRefreshEnabled(false);
00247     KHTMLView *htmlWidget = m_preview->view();
00248     htmlWidget->setMarginWidth(4);
00249     htmlWidget->setMarginHeight(4);
00250     htmlWidget->setFocusPolicy(Qt::NoFocus);
00251     htmlWidget->setSizePolicy(
00252         QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
00253     layout = new QVBoxLayout(m_styleUi.htmlFrame);
00254     layout->setMargin(0);
00255     layout->addWidget(htmlWidget);
00256     m_styleUi.htmlFrame->setLayout(layout);
00257     // Add the preview message to the ChatMessagePart
00258     createPreviewMessages();
00259 
00260 
00261 //--------- emoticons tab ---------------------
00262     QWidget *emoticonsWidget = new QWidget(m_tab);
00263     m_emoticonsUi.setupUi(emoticonsWidget);
00264     m_tab->addTab(emoticonsWidget, i18n("&Emoticons"));
00265 
00266     m_emoticonsUi.icon_theme_list->setItemDelegate(new EmoticonThemeDelegate(this));
00267     addConfig( Kopete::AppearanceSettings::self(), emoticonsWidget );
00268 
00269     connect(m_emoticonsUi.icon_theme_list, SIGNAL(itemSelectionChanged()),
00270         this, SLOT(slotSelectedEmoticonsThemeChanged()));
00271     connect(m_emoticonsUi.btnInstallTheme, SIGNAL(clicked()),
00272         this, SLOT(slotInstallEmoticonTheme()));
00273 
00274     connect(m_emoticonsUi.btnGetThemes, SIGNAL(clicked()),
00275         this, SLOT(slotGetEmoticonThemes()));
00276     connect(m_emoticonsUi.btnRemoveTheme, SIGNAL(clicked()),
00277         this, SLOT(slotRemoveEmoticonTheme()));
00278 
00279 //--------- colors tab --------------------------
00280     QWidget *colorsWidget = new QWidget(m_tab);
00281     m_colorsUi.setupUi(colorsWidget);
00282     m_tab->addTab(colorsWidget, i18n("Colors && Fonts"));
00283     addConfig( Kopete::AppearanceSettings::self(), colorsWidget );
00284 
00285     load();
00286 }
00287 
00288 ChatWindowConfig::~ChatWindowConfig()
00289 {
00290     if (m_previewChatSession)
00291     {
00292         Kopete::ChatSessionManager::self()->removeSession(m_previewChatSession);
00293     }
00294 
00295     // Deleting the account will delete jack and myself
00296     delete m_previewAccount;
00297 
00298     delete m_myselfMetaContact;
00299     delete m_jackMetaContact;
00300 
00301     delete m_previewProtocol;
00302 }
00303 
00304 
00305 void ChatWindowConfig::save()
00306 {
00307     KCModule::save();
00308 //  kDebug(14000) << "called.";
00309 
00310     KopeteChatWindowSettings *settings = KopeteChatWindowSettings::self();
00311 
00312     // Get the styleName
00313     if(m_currentStyle)
00314     {
00315         kDebug(14000) << m_currentStyle->getStyleName();
00316         settings->setStyleName( m_currentStyle->getStyleName() );
00317     }
00318     // Get and save the styleVariant
00319     if( !m_currentVariantMap.empty() )
00320     {
00321         kDebug(14000) << m_currentVariantMap[ m_styleUi.variantList->currentText()];
00322         settings->setStyleVariant( m_currentVariantMap[m_styleUi.variantList->currentText()] );
00323     }
00324 
00325     Kopete::AppearanceSettings *appearanceSettings = Kopete::AppearanceSettings::self();
00326     QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem();
00327     
00328     if (item)
00329         appearanceSettings->setEmoticonTheme( item->text() );
00330 
00331     appearanceSettings->writeConfig();
00332     settings->writeConfig();
00333     m_styleChanged = false;
00334 
00335     load();
00336 }
00337 
00338 void ChatWindowConfig::load()
00339 {
00340     KCModule::load();
00341 
00342     //we will change the state of somme controls, which will call some signals.
00343     //so to don't refresh everything several times, we memorize we are loading.
00344     m_loading=true;
00345 
00346     // Look for available chat window styles.
00347     slotLoadChatStyles();
00348 
00349     // Look for available emoticons themes
00350     updateEmoticonList();
00351 
00352     m_loading=false;
00353     slotUpdateChatPreview();
00354 }
00355 
00356 void ChatWindowConfig::slotLoadChatStyles()
00357 {
00358     m_styleUi.styleList->clear();
00359 
00360     QStringList availableStyles;
00361     availableStyles = ChatWindowStyleManager::self()->getAvailableStyles();
00362     if( availableStyles.empty() )
00363         kDebug(14000) << "Warning, available styles is empty !";
00364 
00365     foreach( const QString& styleName, availableStyles )
00366     {
00367         // Insert style name into the listbox
00368         m_styleUi.styleList->insertItem( styleName, 0 );
00369 
00370         if( styleName == KopeteChatWindowSettings::self()->styleName() )
00371         {
00372             kDebug(14000) << "Restoring saved style: " << styleName;
00373 
00374             m_styleUi.styleList->setSelected( m_styleUi.styleList->firstItem(), true );
00375         }
00376     }
00377 
00378     m_styleUi.styleList->sort();
00379 }
00380 
00381 
00382 void ChatWindowConfig::slotChatStyleSelected()
00383 {
00384     // Retrieve variant list.
00385     QString styleName = m_styleUi.styleList->selectedItem()->text();
00386     m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
00387 
00388     if(m_currentStyle)
00389     {
00390         m_currentVariantMap = m_currentStyle->getVariants();
00391         kDebug(14000) << "Loading style: " << m_currentStyle->getStyleName();
00392 
00393         // Update the variant list based on current style.
00394         m_styleUi.variantList->clear();
00395 
00396         // Add the no variant item to the list
00397         // TODO: Use default name variant from Info.plist
00398         // TODO: Select default variant from Info.plist
00399         m_styleUi.variantList->addItem( i18n("(No Variant)") );
00400 
00401         ChatWindowStyle::StyleVariants::ConstIterator it, itEnd = m_currentVariantMap.constEnd();
00402         int currentIndex = 0;
00403         for(it = m_currentVariantMap.constBegin(); it != itEnd; ++it)
00404         {
00405             // Insert variant name into the combobox.
00406             m_styleUi.variantList->addItem( it.key() );
00407 
00408             if( it.value() == KopeteChatWindowSettings::self()->styleVariant() )
00409                 m_styleUi.variantList->setCurrentIndex(currentIndex+1);
00410 
00411             currentIndex++;
00412         }
00413 
00414         // Update the preview
00415         slotUpdateChatPreview();
00416         // Get the first variant to preview
00417         // Check if the current style has variants.
00418         if( !m_currentVariantMap.empty() ) {
00419             m_preview->setStyleVariant(m_currentVariantMap[0]);
00420             m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( QString() ) );
00421         }
00422 
00423         emitChanged();
00424     }
00425 }
00426 
00427 void ChatWindowConfig::slotChatStyleVariantSelected(const QString &variantName)
00428 {
00429 //  kDebug(14000) << variantName;
00430 //  kDebug(14000) << m_currentVariantMap[variantName];
00431 
00432     // enable the 'Use compact' checkbox depending on whether the selected variant exists in compact
00433     // form
00434     QString styleName = m_styleUi.styleList->selectedItem()->text();
00435     m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
00436     if ( m_styleUi.variantList->currentIndex() == 0 ) {
00437         m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( "" ) );
00438     }
00439     else {
00440         m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( variantName ) );
00441     }
00442     // Update the preview
00443     m_preview->setStyleVariant(m_currentVariantMap[variantName]);
00444     emitChanged();
00445 }
00446 
00447 void ChatWindowConfig::slotInstallChatStyle()
00448 {
00449     KUrl styleToInstall = KFileDialog::getOpenUrl( KUrl(), QString::fromUtf8("application/zip application/x-compressed-tar application/x-bzip-compressed-tar"), this, i18n("Choose Chat Window style to install.") );
00450 
00451     if( !styleToInstall.isEmpty() )
00452     {
00453         QString stylePath;
00454         if( KIO::NetAccess::download( styleToInstall, stylePath, this ) )
00455         {
00456             int styleInstallReturn = 0;
00457             styleInstallReturn = ChatWindowStyleManager::self()->installStyle( stylePath );
00458             switch(styleInstallReturn)
00459             {
00460                 case ChatWindowStyleManager::StyleCannotOpen:
00461                 {
00462                     KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("The specified archive cannot be opened.\nMake sure that the archive is valid ZIP or TAR archive."), i18n("Cannot open archive") );
00463                     break;
00464                 }
00465                 case ChatWindowStyleManager::StyleNoDirectoryValid:
00466                 {
00467                     KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("Could not find a suitable place to install the Chat Window style in user directory."), i18n("Cannot find styles directory") );
00468                     break;
00469                 }
00470                 case ChatWindowStyleManager::StyleNotValid:
00471                     KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("The specified archive does not contain a valid Chat Window style."), i18n("Invalid Style") );
00472                     break;
00473                 case ChatWindowStyleManager::StyleInstallOk:
00474                 {
00475                     KMessageBox::queuedMessageBox( this, KMessageBox::Information, i18n("The Chat Window style was successfully installed."), i18n("Install successful") );
00476                     break;
00477                 }
00478                 case ChatWindowStyleManager::StyleUnknow:
00479                 default:
00480                 {
00481                     KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("An unknow error occurred while trying to install the Chat Window style."), i18n("Unknow error") );
00482                     break;
00483                 }
00484             }
00485 
00486             // removeTempFile check if the file is a temp file, so it's ok for local files.
00487             KIO::NetAccess::removeTempFile( stylePath );
00488         }
00489     }
00490 }
00491 
00492 void ChatWindowConfig::slotDeleteChatStyle()
00493 {
00494     if (!m_styleUi.styleList->selectedItem())
00495     {
00496         return; // nothing selected
00497     }
00498 
00499     QString styleName = m_styleUi.styleList->selectedItem()->text();
00500     if( ChatWindowStyleManager::self()->removeStyle(styleName) )
00501     {
00502         KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18nc("@info", "The style <resource>%1</resource> was successfully deleted.", styleName));
00503         emitChanged();
00504     }
00505     else
00506     {
00507         KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, i18nc("@info", "An error occurred while trying to delete the <resource>%1</resource> style. Your account might not have permission to remove it.", styleName));
00508     }
00509 }
00510 
00511 void ChatWindowConfig::slotGetChatStyles()
00512 {
00513 #ifdef __GNUC__
00514 #warning "Port KNS changes!"
00515 #endif
00516 #if 0
00517     // we need this because KNewStuffGeneric's install function isn't clever enough
00518     KopeteStyleNewStuff *kopeteNewStuff = new KopeteStyleNewStuff( "kopete/chatstyle", this );
00519     KNS::Engine *engine = new KNS::Engine( kopeteNewStuff, "kopete/chatstyle", this );
00520     KNS::DownloadDialog *downloadDialog = new KNS::DownloadDialog( engine, this );
00521     downloadDialog->setCategory( "kopete/chatstyle" );
00522     // you have to do this by hand when providing your own Engine
00523     KNS::ProviderLoader *provider = new KNS::ProviderLoader( this );
00524     QObject::connect( provider, SIGNAL( providersLoaded(Provider::List*) ), downloadDialog, SLOT( slotProviders (Provider::List *) ) );
00525     provider->load( "kopete/chatstyle", "http://download.kde.org/khotnewstuff/kopetestyles12-providers.xml" );
00526     downloadDialog->exec();
00527     delete downloadDialog;
00528     delete kopeteNewStuff;
00529     delete engine;
00530 #endif
00531 }
00532 
00533 void ChatWindowConfig::createPreviewChatSession()
00534 {
00535     m_previewProtocol = new FakeProtocol( KComponentData(QByteArray("kopete-preview-chatwindowstyle")), 0 ); m_previewProtocol->setObjectName( QLatin1String("kopete-preview-chatwindowstyle") );
00536     m_previewAccount = new FakeAccount(m_previewProtocol, QString("previewaccount"));
00537 
00538     // Create fake meta/contacts
00539     m_myselfMetaContact = new Kopete::MetaContact();
00540     m_myselfMetaContact->setTemporary();
00541     m_myselfMetaContact->setDisplayName(i18n("Myself"));
00542     m_myselfMetaContact->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
00543 
00544     m_myself = new FakeContact(m_previewAccount, i18nc("This is the myself preview contact id", "myself@preview"), m_myselfMetaContact);
00545     m_myself->setNickName(i18nc("This is the myself preview contact nickname", "Myself"));
00546 
00547     m_jackMetaContact = new Kopete::MetaContact();
00548     m_jackMetaContact->setTemporary();
00549     m_jackMetaContact->setDisplayName(i18n("Jack"));
00550     m_jackMetaContact->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
00551 
00552     m_jack = new FakeContact(m_previewAccount, i18nc("This is the other preview contact id", "jack@preview"), m_jackMetaContact);
00553     m_jack->setNickName(i18nc("This is the other preview contact nickname", "Jack"));
00554 
00555     m_previewAccount->setMyself(m_myself);
00556 
00557     Kopete::ContactPtrList contactList;
00558     contactList.append(m_jack);
00559     // Create fakeChatSession
00560     m_previewChatSession = Kopete::ChatSessionManager::self()->create(m_myself, contactList, m_previewProtocol);
00561     m_previewChatSession->setDisplayName("Preview Session");
00562 }
00563 
00564 void ChatWindowConfig::createPreviewMessages()
00565 {
00566     Kopete::Message msgIn( m_jack,m_myself );
00567     msgIn.setPlainBody( i18n( "Hello, this is an incoming message :-)" ) );
00568     msgIn.setDirection( Kopete::Message::Inbound );
00569 
00570     Kopete::Message msgIn2( m_jack, m_myself );
00571     msgIn2.setPlainBody( i18n( "Hello, this is an incoming consecutive message." ) );
00572     msgIn2.setDirection( Kopete::Message::Inbound );
00573 
00574     Kopete::Message msgOut( m_myself, m_jack );
00575     msgOut.setPlainBody( i18n( "Ok, this is an outgoing message" ) );
00576     msgOut.setDirection( Kopete::Message::Outbound );
00577 
00578     Kopete::Message msgOut2( m_myself, m_jack );
00579     msgOut2.setPlainBody( i18n( "Ok, an outgoing consecutive message." ) );
00580     msgOut2.setDirection( Kopete::Message::Outbound );
00581 
00582     Kopete::Message msgCol( m_jack, m_myself );
00583     msgCol.setPlainBody( i18n("Here is an incoming colored message.") );
00584     msgCol.setDirection( Kopete::Message::Inbound );
00585     msgCol.setForegroundColor( QColor( "DodgerBlue" ) );
00586     msgCol.setBackgroundColor( QColor( "LightSteelBlue" ) );
00587 
00588     Kopete::Message msgInt( m_jack, m_myself );
00589     msgInt.setPlainBody( i18n( "This is an internal message" ) );
00590     msgInt.setDirection( Kopete::Message::Internal );
00591 
00592     Kopete::Message msgAct( m_jack, m_myself );
00593     msgAct.setPlainBody( i18n( "performed an action" ) );
00594     msgAct.setType( Kopete::Message::TypeAction );
00595     msgAct.setDirection( Kopete::Message::Inbound );
00596 
00597     Kopete::Message msgHigh( m_jack, m_myself );
00598     msgHigh.setPlainBody( i18n( "This is a highlighted message" ) );
00599     msgHigh.setDirection( Kopete::Message::Inbound );
00600     msgHigh.setImportance( Kopete::Message::Highlight );
00601 
00602     // This is a UTF-8 string btw.
00603     Kopete::Message msgRightToLeft( m_myself, m_jack );
00604     msgRightToLeft.setPlainBody( i18nc("This special UTF-8 string is to test if the style support Right-to-Left language display.", "הודעות טקסט") );
00605     msgRightToLeft.setDirection( Kopete::Message::Outbound );
00606 
00607     Kopete::Message msgBye ( m_myself, m_jack );
00608     msgBye.setPlainBody( i18n("Bye") );
00609     msgBye.setDirection( Kopete::Message::Outbound );
00610 
00611     // Add the messages to ChatMessagePart
00612     m_preview->appendMessage(msgIn);
00613     m_preview->appendMessage(msgIn2);
00614     m_preview->appendMessage(msgOut);
00615     m_preview->appendMessage(msgOut2);
00616     m_preview->appendMessage(msgCol);
00617     m_preview->appendMessage(msgInt);
00618     m_preview->appendMessage(msgAct);
00619     m_preview->appendMessage(msgHigh);
00620     m_preview->appendMessage(msgRightToLeft);
00621     m_preview->appendMessage(msgBye);
00622 }
00623 
00624 void ChatWindowConfig::slotUpdateChatPreview()
00625 {
00626     if(m_loading || !m_currentStyle)
00627         return;
00628 
00629     // Update the preview
00630     m_preview->setStyle(m_currentStyle);
00631 
00632     emitChanged();
00633 }
00634 
00635 void ChatWindowConfig::slotUpdateEmoticonsButton(bool _b)
00636 {
00637     QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem();
00638     if (!item)
00639         return;
00640     QString themeName = item->text();
00641     QFileInfo fileInf(KGlobal::dirs()->findResource("emoticons", themeName+'/'));
00642     m_emoticonsUi.btnRemoveTheme->setEnabled( _b && fileInf.isWritable());
00643     m_emoticonsUi.btnGetThemes->setEnabled( false );
00644 }
00645 
00646 void ChatWindowConfig::updateEmoticonList()
00647 {
00648     KStandardDirs dir;
00649 
00650     m_emoticonsUi.icon_theme_list->clear(); // Wipe out old list
00651     // Get a list of directories in our icon theme dir
00652     QStringList themeDirs = KGlobal::dirs()->findDirs("emoticons", "");
00653     // loop adding themes from all dirs into theme-list
00654     for( int x = 0;x < themeDirs.count();x++)
00655     {
00656         QDir themeQDir(themeDirs[x]);
00657         themeQDir.setFilter( QDir::Dirs ); // only scan for subdirs
00658         themeQDir.setSorting( QDir::Name ); // I guess name is as good as any
00659         for(unsigned int y = 0; y < themeQDir.count(); y++)
00660         {
00661             QStringList themes = themeQDir.entryList(QDir::Dirs, QDir::Name);
00662 
00663             // We don't care for '.' and '..'
00664             if ( themeQDir[y] != "." && themeQDir[y] != ".." )
00665             {
00666                 // Add ourselves to the list, using our directory name  FIXME:  use the first emoticon of the theme.
00667                 QListWidgetItem *item = new EmoticonThemeItem(themeQDir[y]);
00668                 m_emoticonsUi.icon_theme_list->addItem(item);
00669             }
00670         }
00671     }
00672 
00673     // Where is that theme in our big-list-o-themes?
00674 
00675     QList<QListWidgetItem*> items = m_emoticonsUi.icon_theme_list->findItems( Kopete::AppearanceSettings::self()->emoticonTheme(), Qt::MatchExactly );
00676 
00677     if (items.count()) // found it... make it the currently selected theme
00678         m_emoticonsUi.icon_theme_list->setCurrentItem( items.first() );
00679     else // Er, it's not there... select the current item
00680         m_emoticonsUi.icon_theme_list->setCurrentItem( 0 );
00681 }
00682 
00683 void ChatWindowConfig::slotSelectedEmoticonsThemeChanged()
00684 {
00685     QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem();
00686     if (!item)
00687         return;
00688     QString themeName = item->text();
00689     QFileInfo fileInf(KGlobal::dirs()->findResource("emoticons", themeName+'/'));
00690     m_emoticonsUi.btnRemoveTheme->setEnabled( fileInf.isWritable() );
00691 
00692     emitChanged();
00693 }
00694 
00695 void ChatWindowConfig::slotInstallEmoticonTheme()
00696 {
00697     KUrl themeURL = KUrlRequesterDialog::getUrl(QString::null, this,    //krazy:exclude=nullstrassign for old broken gcc
00698             i18n("Drag or Type Emoticon Theme URL"));
00699     if ( themeURL.isEmpty() )
00700         return;
00701 
00702     //TODO: support remote theme files!
00703     if ( !themeURL.isLocalFile() )
00704     {
00705         KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("Sorry, emoticon themes must be installed from local files."),
00706                                        i18n("Could Not Install Emoticon Theme") );
00707         return;
00708     }
00709 
00710     Kopete::Global::installEmoticonTheme( themeURL.path() );
00711     updateEmoticonList();
00712 }
00713 
00714 void ChatWindowConfig::slotRemoveEmoticonTheme()
00715 {
00716     QListWidgetItem *selected = m_emoticonsUi.icon_theme_list->currentItem();
00717     if(!selected)
00718         return;
00719 
00720     QString themeName = selected->text();
00721 
00722     QString question=i18n("<qt>Are you sure you want to remove the "
00723             "<strong>%1</strong> emoticon theme?<br />"
00724             "<br />"
00725             "This will delete the files installed by this theme.</qt>",
00726         themeName);
00727 
00728         int res = KMessageBox::warningContinueCancel(this, question, i18n("Confirmation"),KStandardGuiItem::del());
00729     if (res!=KMessageBox::Continue)
00730         return;
00731 
00732     KUrl themeUrl(KGlobal::dirs()->findResource("emoticons", themeName+'/'));
00733     KIO::NetAccess::del(themeUrl, this);
00734 
00735     updateEmoticonList();
00736 }
00737 
00738 void ChatWindowConfig::slotGetEmoticonThemes()
00739 {
00740     KConfigGroup config(KGlobal::config(), "KNewStuff");
00741     config.writeEntry( "ProvidersUrl",
00742                         "http://download.kde.org/khotnewstuff/emoticons-providers.xml" );
00743     config.writeEntry( "StandardResource", "emoticons" );
00744     config.writeEntry( "Uncompress", "application/x-gzip" );
00745     config.sync();
00746 
00747 #ifdef __GNUC__
00748 #warning "Port KNS changes!"
00749 #endif
00750 #if 0
00751     KNS::DownloadDialog::open( "emoticons", i18n( "Get New Emoticons") );
00752 #endif
00753 
00754     updateEmoticonList();
00755 }
00756 
00757 
00758 void ChatWindowConfig::emitChanged()
00759 {
00760     emit changed( true );
00761 }
00762 
00763 #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