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

kopete/kopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • kopete
  • config
  • chatwindow
chatwindowconfig.cpp
Go to the documentation of this file.
1 /*
2  chatwindowconfig.cpp - Kopete Look Feel Config
3 
4  Copyright (c) 2005-2006 by Michaël Larouche <larouche@kde.org>
5  Copyright (c) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
6  Copyright (c) 2007 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
7 
8  Kopete (c) 2005-2007 by the Kopete developers <kopete-devel@kde.org>
9 
10  *************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  *************************************************************************
18 */
19 
20 #include "chatwindowconfig.h"
21 #include "emoticonthemedelegate.h"
22 #include "emoticonthemeitem.h"
23 #include "kopetebehaviorsettings.h"
24 
25 #include <QCheckBox>
26 #include <QDir>
27 #include <QLayout>
28 #include <QSpinBox>
29 #include <QSlider>
30 #include <QLabel>
31 #include <QPixmap>
32 #include <QVBoxLayout>
33 
34 #include <kdeversion.h>
35 #include <kinputdialog.h>
36 
37 #include <kcolorcombo.h>
38 #include <kcolorbutton.h>
39 #include <kdebug.h>
40 #include <kfontrequester.h>
41 #include <kpluginfactory.h>
42 #include <kio/netaccess.h>
43 #include <khtmlview.h>
44 #include <klineedit.h>
45 #include <klocale.h>
46 #include <kmessagebox.h>
47 #include <kpushbutton.h>
48 #include <kstandarddirs.h>
49 #include <kurlrequesterdialog.h>
50 #include <krun.h>
51 #include <kfiledialog.h>
52 #include <kurl.h>
53 #include <kemoticons.h>
54 #include <KCMultiDialog>
55 
56 // KNewStuff
57 #include <knewstuff2/engine.h>
58 
59 // For Kopete Chat Window Style configuration and preview.
60 #include <kopetechatwindowstylemanager.h>
61 #include <kopetechatwindowstyle.h>
62 #include <chatmessagepart.h>
63 #include <kopetecontactlist.h>
64 
65 
66 // Things we fake to get the message preview to work
67 #include <kopeteprotocol.h>
68 #include <kopetemetacontact.h>
69 #include <kopeteaccount.h>
70 #include <kopeteidentity.h>
71 #include <kopetecontact.h>
72 #include <kopetemessage.h>
73 #include <kopetechatsession.h>
74 #include <kopetechatsessionmanager.h>
75 #include <kopetestatusmessage.h>
76 #include <kopeteappearancesettings.h>
77 
78 #include "kopeteemoticons.h"
79 
80 #include "kopeteglobal.h"
81 
82 #include "kopetechatwindowsettings.h"
83 
84 K_PLUGIN_FACTORY( KopeteChatWindowConfigFactory,
85  registerPlugin<ChatWindowConfig>(); )
86 K_EXPORT_PLUGIN( KopeteChatWindowConfigFactory("kcm_kopete_chatwindowconfig") )
87 
88 // Reimplement Kopete::Contact and its abstract method
89 // This is for style preview.
90 class FakeContact : public Kopete::Contact
91 {
92 public:
93  FakeContact (Kopete::Account *account, const QString &id, Kopete::MetaContact *mc ) : Kopete::Contact( account, id, mc ) {}
94  virtual Kopete::ChatSession *manager(Kopete::Contact::CanCreateFlags /*c*/) { return 0L; }
95  virtual void slotUserInfo() {}
96 };
97 
98 // This is for style preview.
99 class FakeProtocol : public Kopete::Protocol
100 {
101 public:
102 FakeProtocol( const KComponentData &instance, QObject *parent ) : Kopete::Protocol(instance, parent){}
103 Kopete::Account* createNewAccount( const QString &/*accountId*/ ){return 0L;}
104 AddContactPage* createAddContactWidget( QWidget */*parent*/, Kopete::Account */*account*/){return 0L;}
105 KopeteEditAccountWidget* createEditAccountWidget( Kopete::Account */*account*/, QWidget */*parent */){return 0L;}
106 };
107 
108 // This is for style preview.
109 class FakeIdentity : public Kopete::Identity
110 {
111  public:
112  FakeIdentity() : Kopete::Identity("Preview Identity") {};
113 };
114 
115 // This is for style preview.
116 class FakeAccount : public Kopete::Account
117 {
118 public:
119  FakeAccount(Kopete::Protocol *parent, const QString &accountID) : Kopete::Account(parent, accountID)
120  {
121  m_identity = new FakeIdentity();
122  setIdentity(m_identity);
123  }
124 
125  void setMyself(Kopete::Contact *myself)
126  {
127  Kopete::Account::setMyself(myself);
128  }
129 
130  ~FakeAccount()
131  {
132  delete m_identity;
133  }
134 
135 bool createContact( const QString &/*contactId*/, Kopete::MetaContact */*parentContact*/ ){return true;}
136 void connect( const Kopete::OnlineStatus& /*initialStatus*/){}
137 void disconnect(){}
138 void setOnlineStatus( const Kopete::OnlineStatus& /*status*/, const Kopete::StatusMessage &/*reason*/, const OnlineStatusOptions&/*options*/){}
139 void setStatusMessage(const Kopete::StatusMessage& /*statusMessage*/){}
140 
141 private:
142  FakeIdentity *m_identity;
143 };
144 
145 ChatWindowConfig::ChatWindowConfig(QWidget *parent, const QVariantList &args )
146  : KCModule( KopeteChatWindowConfigFactory::componentData(), parent, args ),
147  m_currentStyle (0L), m_loading(false),
148  m_previewProtocol(0L), m_previewAccount(0L),
149  m_jackMetaContact(0L), m_myself(0L), m_jack(0L)
150 {
151  KConfigGroup config(KGlobal::config(), "ChatWindowSettings");
152 
153  QVBoxLayout *layout = new QVBoxLayout(this);
154  // since KSetting::Dialog has margins here, we don't need our own.
155  layout->setContentsMargins( 0, 0, 0, 0);
156  m_tab = new QTabWidget(this);
157  layout->addWidget(m_tab);
158 
159 //--------- style tab ---------------------
160  QWidget *styleWidget = new QWidget(m_tab);
161  m_styleUi.setupUi(styleWidget);
162  m_tab->addTab(styleWidget, i18n("&Style"));
163  addConfig( KopeteChatWindowSettings::self(), styleWidget );
164 
165  connect(m_styleUi.styleList, SIGNAL(currentTextChanged(QString)),
166  this, SLOT(slotChatStyleSelected(QString)));
167  connect(m_styleUi.variantList, SIGNAL(activated(QString)),
168  this, SLOT(slotChatStyleVariantSelected(QString)));
169  connect(m_styleUi.deleteButton, SIGNAL(clicked()),
170  this, SLOT(slotDeleteChatStyle()));
171  connect(m_styleUi.installButton, SIGNAL(clicked()),
172  this, SLOT(slotInstallChatStyle()));
173  connect(m_styleUi.btnGetStyles, SIGNAL(clicked()),
174  this, SLOT(slotGetChatStyles()));
175 
176  m_styleUi.deleteButton->setIcon(KIcon("edit-delete"));
177  m_styleUi.installButton->setIcon(KIcon("document-import"));
178  m_styleUi.btnGetStyles->setIcon(KIcon("get-hot-new-stuff"));
179 
180  // Show the available styles when the Manager has finish to load the styles.
181  connect(ChatWindowStyleManager::self(), SIGNAL(loadStylesFinished()), this, SLOT(slotLoadChatStyles()));
182 
183  // Create the fake Chat Session
184  createPreviewChatSession();
185  m_preview = new ChatMessagePart(m_previewChatSession, m_styleUi.htmlFrame);
186  m_preview->setJScriptEnabled(false);
187  m_preview->setJavaEnabled(false);
188  m_preview->setPluginsEnabled(false);
189  m_preview->setMetaRefreshEnabled(false);
190  KHTMLView *htmlWidget = m_preview->view();
191  htmlWidget->setMarginWidth(4);
192  htmlWidget->setMarginHeight(4);
193  htmlWidget->setFocusPolicy(Qt::NoFocus);
194  htmlWidget->setSizePolicy(
195  QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
196  layout = new QVBoxLayout(m_styleUi.htmlFrame);
197  layout->setMargin(0);
198  layout->addWidget(htmlWidget);
199  m_styleUi.htmlFrame->setLayout(layout);
200  // Add the preview message to the ChatMessagePart
201  createPreviewMessages();
202 
203 
204 //--------- emoticons tab ---------------------
205  QWidget *emoticonsWidget = new QWidget(m_tab);
206  m_emoticonsUi.setupUi(emoticonsWidget);
207  m_tab->addTab(emoticonsWidget, i18n("&Emoticons"));
208 
209  m_emoticonsUi.icon_theme_list->setItemDelegate(new EmoticonThemeDelegate(this));
210  addConfig( Kopete::AppearanceSettings::self(), emoticonsWidget );
211 
212  connect(m_emoticonsUi.icon_theme_list, SIGNAL(itemSelectionChanged()),
213  this, SLOT(emitChanged()));
214 
215  connect(m_emoticonsUi.btnManageThemes, SIGNAL(clicked()),
216  this, SLOT(slotManageEmoticonThemes()));
217 
218 //--------- colors tab --------------------------
219  QWidget *colorsWidget = new QWidget(m_tab);
220  m_colorsUi.setupUi(colorsWidget);
221  m_tab->addTab(colorsWidget, i18n("Colors && Fonts"));
222  addConfig( Kopete::AppearanceSettings::self(), colorsWidget );
223 
224 //--------- tab tab --------------------------
225  QWidget *tabWidget = new QWidget(m_tab);
226  m_tabUi.setupUi(tabWidget);
227  m_tab->addTab(tabWidget, i18n("&Tabs"));
228  addConfig( Kopete::BehaviorSettings::self(), tabWidget );
229 
230  load();
231 }
232 
233 ChatWindowConfig::~ChatWindowConfig()
234 {
235  if (m_previewChatSession)
236  {
237  Kopete::ChatSessionManager::self()->removeSession(m_previewChatSession);
238  }
239 
240  // Deleting the account will delete jack and myself
241  delete m_previewAccount;
242 
243  delete m_jackMetaContact;
244 
245  delete m_previewProtocol;
246 }
247 
248 
249 void ChatWindowConfig::save()
250 {
251  KCModule::save();
252 // kDebug(14000) << "called.";
253 
254  KopeteChatWindowSettings *settings = KopeteChatWindowSettings::self();
255 
256  // Get the styleName
257  if(m_currentStyle)
258  {
259  kDebug(14000) << m_currentStyle->getStyleName();
260  settings->setStyleName( m_currentStyle->getStyleName() );
261  }
262  // Get and save the styleVariant
263  if( !m_currentVariantMap.empty() )
264  {
265  kDebug(14000) << m_currentVariantMap[ m_styleUi.variantList->currentText()];
266  settings->setStyleVariant( m_currentVariantMap[m_styleUi.variantList->currentText()] );
267  }
268 
269  Kopete::AppearanceSettings *appearanceSettings = Kopete::AppearanceSettings::self();
270  QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem();
271 
272  if (item)
273  KEmoticons::setTheme( item->text() );
274 
275  // Ugly hacks, this will emit the kcfg signals
276  appearanceSettings->setChatTextColor(m_colorsUi.kcfg_chatTextColor->color());
277  appearanceSettings->setUseEmoticons(m_emoticonsUi.kcfg_useEmoticons->isChecked());
278  settings->setChatFmtOverride(m_colorsUi.kcfg_chatFmtOverride->isChecked());
279 
280  appearanceSettings->writeConfig();
281  settings->writeConfig();
282 
283  load();
284 }
285 
286 void ChatWindowConfig::load()
287 {
288  KCModule::load();
289 
290  //we will change the state of somme controls, which will call some signals.
291  //so to don't refresh everything several times, we memorize we are loading.
292  m_loading=true;
293 
294  // Look for available chat window styles.
295  slotLoadChatStyles();
296 
297  // Look for available emoticons themes
298  updateEmoticonList();
299 
300  m_loading=false;
301  slotUpdateChatPreview();
302 }
303 
304 void ChatWindowConfig::slotLoadChatStyles()
305 {
306  m_styleUi.styleList->clear();
307 
308  QStringList availableStyles;
309  availableStyles = ChatWindowStyleManager::self()->getAvailableStyles();
310  if( availableStyles.empty() )
311  kDebug(14000) << "Warning, available styles is empty !";
312 
313  foreach( const QString& styleName, availableStyles )
314  {
315  // Insert style name into the listbox
316  m_styleUi.styleList->insertItem( 0, styleName );
317  }
318 
319  m_styleUi.styleList->setSortingEnabled( true );
320 
321  QString currentStyle = KopeteChatWindowSettings::self()->styleName();
322  QList<QListWidgetItem *> items = m_styleUi.styleList->findItems( currentStyle, Qt::MatchFixedString | Qt::MatchCaseSensitive );
323  if( items.count() > 0 )
324  {
325  kDebug(14000) << "Restoring saved style: " << currentStyle;
326 
327  m_styleUi.styleList->setCurrentItem( items[0] );
328  m_styleUi.styleList->scrollToItem( items[0] );
329  }
330 }
331 
332 
333 void ChatWindowConfig::slotChatStyleSelected(const QString &styleName)
334 {
335  if (styleName.isEmpty())
336  return;
337  // Retrieve variant list.
338  m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
339 
340  if(m_currentStyle)
341  {
342  m_currentVariantMap = m_currentStyle->getVariants();
343  kDebug(14000) << "Loading style: " << m_currentStyle->getStyleName();
344 
345  // Update the variant list based on current style.
346  m_styleUi.variantList->clear();
347 
348  // Add the no variant item to the list
349  // TODO: Use default name variant from Info.plist
350  // TODO: Select default variant from Info.plist
351  m_styleUi.variantList->addItem( i18n("(No Variant)") );
352 
353  ChatWindowStyle::StyleVariants::ConstIterator it, itEnd = m_currentVariantMap.constEnd();
354  int currentIndex = 0;
355  for(it = m_currentVariantMap.constBegin(); it != itEnd; ++it)
356  {
357  // Insert variant name into the combobox.
358  m_styleUi.variantList->addItem( it.key() );
359 
360  if( it.value() == KopeteChatWindowSettings::self()->styleVariant() )
361  m_styleUi.variantList->setCurrentIndex(currentIndex+1);
362 
363  currentIndex++;
364  }
365 
366  // Update the preview
367  slotUpdateChatPreview();
368  // Get the first variant to preview
369  // Check if the current style has variants.
370  if( !m_currentVariantMap.empty() ) {
371  m_preview->setStyleVariant(m_currentVariantMap[0]);
372  m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( QString() ) );
373  }
374 
375  emitChanged();
376  }
377  else {
378  m_styleUi.variantList->clear();
379  slotUpdateChatPreview();
380  }
381 }
382 
383 void ChatWindowConfig::slotChatStyleVariantSelected(const QString &variantName)
384 {
385 // kDebug(14000) << variantName;
386 // kDebug(14000) << m_currentVariantMap[variantName];
387 
388  // enable the 'Use compact' checkbox depending on whether the selected variant exists in compact
389  // form
390  QString styleName = m_styleUi.styleList->currentItem()->text();
391  m_currentStyle = ChatWindowStyleManager::self()->getStyleFromPool( styleName );
392  if ( !m_currentStyle )
393  return;
394 
395  if ( m_styleUi.variantList->currentIndex() == 0 ) {
396  m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( "" ) );
397  }
398  else {
399  m_styleUi.kcfg_useCompact->setEnabled(m_currentStyle->hasCompact( variantName ) );
400  }
401  // Update the preview
402  m_preview->setStyleVariant(m_currentVariantMap[variantName]);
403  emitChanged();
404 }
405 
406 void ChatWindowConfig::slotInstallChatStyle()
407 {
408  KUrl styleUrl = KFileDialog::getOpenUrl( KUrl(), QString::fromUtf8("application/zip application/x-compressed-tar application/x-bzip-compressed-tar"), this, i18n("Choose Chat Window Style to Install") );
409 
410  if ( styleUrl.isEmpty() ) // dialog got canceled
411  return;
412 
413  int styleInstallReturn = installChatStyle( styleUrl );
414 
415  switch(styleInstallReturn)
416  {
417  case ChatWindowStyleManager::StyleCannotOpen:
418  {
419  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") );
420  break;
421  }
422  case ChatWindowStyleManager::StyleNoDirectoryValid:
423  {
424  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("Could not find a suitable place to install the chat window style."), i18n("Cannot Find Styles Directory") );
425  break;
426  }
427  case ChatWindowStyleManager::StyleNotValid:
428  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("The specified archive does not contain a valid chat window style."), i18n("Invalid Style") );
429  break;
430  case ChatWindowStyleManager::StyleInstallOk:
431  {
432  KMessageBox::queuedMessageBox( this, KMessageBox::Information, i18n("The chat window style was successfully installed."), i18n("Install Successful") );
433  break;
434  }
435  case ChatWindowStyleManager::StyleUnknow:
436  default:
437  {
438  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18n("An unknown error occurred while trying to install the chat window style."), i18n("Unknown Error") );
439  break;
440  }
441  }
442 }
443 
444 int ChatWindowConfig::installChatStyle(const KUrl &styleToInstall)
445 {
446  int styleInstallReturn = ChatWindowStyleManager::StyleCannotOpen;
447 
448  if( !styleToInstall.isEmpty() )
449  {
450  QString stylePath;
451  if( KIO::NetAccess::download( styleToInstall, stylePath, this ) )
452  {
453  styleInstallReturn = ChatWindowStyleManager::self()->installStyle( stylePath );
454 
455  // removeTempFile check if the file is a temp file, so it's ok for local files.
456  KIO::NetAccess::removeTempFile( stylePath );
457  }
458  }
459 
460  return styleInstallReturn;
461 }
462 
463 void ChatWindowConfig::slotDeleteChatStyle()
464 {
465  if (!m_styleUi.styleList->currentItem())
466  {
467  return; // nothing selected
468  }
469 
470  QString styleName = m_styleUi.styleList->currentItem()->text();
471  if( ChatWindowStyleManager::self()->removeStyle(styleName) )
472  {
473  KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18nc("@info", "The Chat Window Style <resource>%1</resource> was successfully deleted.", styleName));
474  emitChanged();
475  }
476  else
477  {
478  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));
479  }
480  slotUpdateChatPreview();
481 }
482 
483 void ChatWindowConfig::slotGetChatStyles()
484 {
485  KConfigGroup configGrp(KGlobal::config(), "KNewStuff2");
486  configGrp.writeEntry("ProvidersUrl", "http://download.kde.org/khotnewstuff/kopetestyles12-providers.xml");
487  configGrp.writeEntry("TargetDir", "kopete_chatstyles");
488  configGrp.sync();
489 
490  KNS::Engine *engine = new KNS::Engine();
491  engine->init(configGrp.config()->name());
492 
493  // FIXME: Upon closing the Settings KCMultiDialog all KCMs are deleted and when reopening
494  // the settings dialog there is no active valid KComponentData, which KNS2 relies on.
495  // Forcing an active one below works around bug 163382, but the problem is somewhere else.
496  KGlobal::setActiveComponent(KopeteChatWindowConfigFactory::componentData());
497 
498  KNS::Entry::List entries = engine->downloadDialogModal(this);
499 
500  if ( entries.size() > 0 )
501  {
502  int correctlyInstalled(0);
503  foreach( KNS::Entry* entry, entries )
504  {
505  if ( entry->status() == KNS::Entry::Installed && entry->installedFiles().size() > 0 )
506  {
507  KUrl styleFile( entry->installedFiles().at(0) );
508  int result = installChatStyle( styleFile );
509 
510  QString packageName(entry->name().representation());
511  QString errorTitle = i18nc("@title:window", "Chat Window Style <resource>%1</resource> installation", packageName);
512  switch(result)
513  {
514  case ChatWindowStyleManager::StyleCannotOpen:
515  {
516  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);
517  break;
518  }
519  case ChatWindowStyleManager::StyleNoDirectoryValid:
520  {
521  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "Could not find a suitable place to install the Chat Window Style <resource>%1</resource>.", packageName), errorTitle );
522  break;
523  }
524  case ChatWindowStyleManager::StyleNotValid:
525  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "The specified archive <filename>%1</filename> does not contain a valid Chat Window Style.", styleFile.pathOrUrl()), errorTitle );
526  break;
527  case ChatWindowStyleManager::StyleInstallOk:
528  {
529  ++correctlyInstalled;
530  break;
531  }
532  case ChatWindowStyleManager::StyleUnknow:
533  default:
534  {
535  KMessageBox::queuedMessageBox( this, KMessageBox::Error, i18nc("@info", "An unknown error occurred while trying to install the Chat Window Style <resource>%1</resource>.", packageName), errorTitle );
536  break;
537  }
538  }
539  }
540  }
541 
542  if ( correctlyInstalled > 0)
543  {
544  KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18np("One Chat Window Style package has been installed.", "%1 Chat Window Style packages have been installed.", correctlyInstalled));
545  }
546  }
547 
548  delete engine;
549 }
550 
551 void ChatWindowConfig::createPreviewChatSession()
552 {
553  m_previewProtocol = new FakeProtocol( KComponentData(QByteArray("kopete-preview-chatwindowstyle")), 0 ); m_previewProtocol->setObjectName( QLatin1String("kopete-preview-chatwindowstyle") );
554  m_previewAccount = new FakeAccount(m_previewProtocol, QString("previewaccount"));
555 
556  m_myself = new FakeContact(m_previewAccount, i18nc("This is the myself preview contact id", "myself@preview"), Kopete::ContactList::self()->myself());
557  m_myself->setNickName(i18nc("This is the myself preview contact nickname", "Myself"));
558 
559  m_jackMetaContact = new Kopete::MetaContact();
560  m_jackMetaContact->setTemporary();
561  m_jackMetaContact->setDisplayName(i18n("Jack"));
562  m_jackMetaContact->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
563 
564  m_jack = new FakeContact(m_previewAccount, i18nc("This is the other preview contact id", "jack@preview"), m_jackMetaContact);
565  m_jack->setNickName(i18nc("This is the other preview contact nickname", "Jack"));
566 
567  m_previewAccount->setMyself(m_myself);
568 
569  Kopete::ContactPtrList contactList;
570  contactList.append(m_jack);
571  // Create fakeChatSession
572  m_previewChatSession = Kopete::ChatSessionManager::self()->create(m_myself, contactList, m_previewProtocol);
573  m_previewChatSession->setDisplayName(i18nc("preview of a chat session", "Preview Session"));
574 }
575 
576 void ChatWindowConfig::createPreviewMessages()
577 {
578  Kopete::Message msgIn( m_jack,m_myself );
579  msgIn.setPlainBody( i18n( "Hello, this is an incoming message :-)" ) );
580  msgIn.setDirection( Kopete::Message::Inbound );
581 
582  Kopete::Message msgIn2( m_jack, m_myself );
583  msgIn2.setPlainBody( i18n( "Hello, this is an incoming consecutive message." ) );
584  msgIn2.setDirection( Kopete::Message::Inbound );
585 
586  Kopete::Message msgOut( m_myself, m_jack );
587  msgOut.setPlainBody( i18n( "Ok, this is an outgoing message" ) );
588  msgOut.setDirection( Kopete::Message::Outbound );
589 
590  Kopete::Message msgOut2( m_myself, m_jack );
591  msgOut2.setPlainBody( i18n( "Ok, an outgoing consecutive message." ) );
592  msgOut2.setDirection( Kopete::Message::Outbound );
593 
594  Kopete::Message msgOut3( m_myself, m_jack );
595  msgOut3.setPlainBody( i18n( "Message that is being sent." ) );
596  msgOut3.setDirection( Kopete::Message::Outbound );
597  msgOut3.setState( Kopete::Message::StateSending );
598 
599  Kopete::Message msgOut4( m_myself, m_jack );
600  msgOut4.setPlainBody( i18n( "Delivered message." ) );
601  msgOut4.setDirection( Kopete::Message::Outbound );
602  msgOut4.setState( Kopete::Message::StateSent );
603 
604  Kopete::Message msgOut5( m_myself, m_jack );
605  msgOut5.setPlainBody( i18n( "Message that cannot be delivered." ) );
606  msgOut5.setDirection( Kopete::Message::Outbound );
607  msgOut5.setState( Kopete::Message::StateError );
608 
609  Kopete::Message msgCol( m_jack, m_myself );
610  msgCol.setPlainBody( i18n("Here is an incoming colored message.") );
611  msgCol.setDirection( Kopete::Message::Inbound );
612  msgCol.setForegroundColor( QColor( "DodgerBlue" ) );
613  msgCol.setBackgroundColor( QColor( "LightSteelBlue" ) );
614 
615  Kopete::Message msgInt( m_jack, m_myself );
616  msgInt.setPlainBody( i18n( "This is an internal message" ) );
617  msgInt.setDirection( Kopete::Message::Internal );
618 
619  Kopete::Message msgAct( m_jack, m_myself );
620  msgAct.setPlainBody( i18n( "performed an action" ) );
621  msgAct.setType( Kopete::Message::TypeAction );
622  msgAct.setDirection( Kopete::Message::Inbound );
623 
624  Kopete::Message msgHigh( m_jack, m_myself );
625  msgHigh.setPlainBody( i18n( "This is a highlighted message" ) );
626  msgHigh.setDirection( Kopete::Message::Inbound );
627  msgHigh.setImportance( Kopete::Message::Highlight );
628 
629  Kopete::Message msgFTRequest( m_jack, m_myself );
630  msgFTRequest.setPlainBody( i18n( "Hello, this is an incoming file transfer request" ) );
631  msgFTRequest.setDirection( Kopete::Message::Inbound );
632  msgFTRequest.setType( Kopete::Message::TypeFileTransferRequest );
633  msgFTRequest.setFileName( "data.pdf" );
634  msgFTRequest.setFileSize( 10000000 );
635 
636  Kopete::Message msgFTRequestDisabled( m_jack, m_myself );
637  msgFTRequestDisabled.setPlainBody( i18n( "Hello, this is a disabled incoming file transfer request" ) );
638  msgFTRequestDisabled.setDirection( Kopete::Message::Inbound );
639  msgFTRequestDisabled.setType( Kopete::Message::TypeFileTransferRequest );
640  msgFTRequestDisabled.setFileName( "data.pdf" );
641  msgFTRequestDisabled.setFileSize( 10000000 );
642  msgFTRequestDisabled.setFileTransferDisabled( true );
643 
644  // This is a UTF-8 string btw.
645  Kopete::Message msgRightToLeft( m_myself, m_jack );
646  msgRightToLeft.setPlainBody( i18nc("This special UTF-8 string is to test if the style supports Right-to-Left language display.", "הודעות טקסט") );
647  msgRightToLeft.setDirection( Kopete::Message::Outbound );
648 
649  Kopete::Message msgBye ( m_myself, m_jack );
650  msgBye.setPlainBody( i18n("Bye") );
651  msgBye.setDirection( Kopete::Message::Outbound );
652 
653  // Add the messages to ChatMessagePart
654  m_preview->appendMessage(msgIn);
655  m_preview->appendMessage(msgIn2);
656  m_preview->appendMessage(msgOut);
657  m_preview->appendMessage(msgOut2);
658  m_preview->appendMessage(msgOut3);
659  m_preview->appendMessage(msgOut4);
660  m_preview->appendMessage(msgOut5);
661  m_preview->appendMessage(msgCol);
662  m_preview->appendMessage(msgInt);
663  m_preview->appendMessage(msgAct);
664  m_preview->appendMessage(msgHigh);
665  m_preview->appendMessage(msgFTRequest);
666  m_preview->appendMessage(msgFTRequestDisabled);
667  m_preview->appendMessage(msgRightToLeft);
668  m_preview->appendMessage(msgBye);
669 }
670 
671 void ChatWindowConfig::slotUpdateChatPreview()
672 {
673  if(m_loading)
674  return;
675 
676  // Update the preview
677  m_preview->setStyle(m_currentStyle);
678 
679  emitChanged();
680 }
681 
682 
683 void ChatWindowConfig::updateEmoticonList()
684 {
685  KStandardDirs dir;
686 
687  m_emoticonsUi.icon_theme_list->clear(); // Wipe out old list
688  // Get a list of directories in our icon theme dir
689  QStringList themeDirs = KGlobal::dirs()->findDirs("emoticons", "");
690  // loop adding themes from all dirs into theme-list
691  for( int x = 0;x < themeDirs.count();x++)
692  {
693  QDir themeQDir(themeDirs[x]);
694  themeQDir.setFilter( QDir::Dirs ); // only scan for subdirs
695  themeQDir.setSorting( QDir::Name ); // I guess name is as good as any
696  for(unsigned int y = 0; y < themeQDir.count(); y++)
697  {
698  QStringList themes = themeQDir.entryList(QDir::Dirs, QDir::Name);
699 
700  // We don't care for '.' and '..'
701  if ( themeQDir[y] != "." && themeQDir[y] != ".." )
702  {
703  // Add ourselves to the list, using our directory name FIXME: use the first emoticon of the theme.
704  QListWidgetItem *item = new EmoticonThemeItem(themeQDir[y]);
705  m_emoticonsUi.icon_theme_list->addItem(item);
706  }
707  }
708  }
709 
710  // Where is that theme in our big-list-o-themes?
711 
712  QList<QListWidgetItem*> items = m_emoticonsUi.icon_theme_list->findItems( KEmoticons::currentThemeName(), Qt::MatchExactly );
713 
714  if (items.count()) // found it... make it the currently selected theme
715  m_emoticonsUi.icon_theme_list->setCurrentItem( items.first() );
716  else // Er, it's not there... select the current item
717  m_emoticonsUi.icon_theme_list->setCurrentItem( 0 );
718 }
719 
720 
721 void ChatWindowConfig::slotManageEmoticonThemes()
722 {
723  // FIXME: Upon closing the Settings KCMultiDialog all KCMs are deleted and when reopening
724  // the settings dialog there is no active valid KComponentData, which KNS2 relies on.
725  // Forcing an active one below works around bug 165919, but the problem is somewhere else.
726  KGlobal::setActiveComponent(KopeteChatWindowConfigFactory::componentData());
727 
728  KCMultiDialog *kcm = new KCMultiDialog( this );
729  kcm->setCaption( i18n( "Configure Emoticon Themes" ) );
730  kcm->addModule( "emoticons" );
731  kcm->exec();
732  updateEmoticonList();
733 }
734 
735 
736 void ChatWindowConfig::emitChanged()
737 {
738  emit changed( true );
739 }
740 
741 #include "chatwindowconfig.moc"
QHash::empty
bool empty() const
QWidget
KopeteChatWindowSettings::setStyleVariant
static void setStyleVariant(const QString &v)
Set Relative path to a CSS variant for the current style.
Definition: kopetechatwindowsettings.h:61
ChatMessagePart::setStyleVariant
void setStyleVariant(const QString &variantPath)
Change the current variant for the current style.
Definition: chatmessagepart.cpp:445
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
ChatMessagePart::appendMessage
void appendMessage(Kopete::Message &message, bool restoring=false)
Appends a message to the messave view.
Definition: chatmessagepart.cpp:474
ChatWindowStyleManager::self
static ChatWindowStyleManager * self()
Singleton access to this class.
Definition: kopetechatwindowstylemanager.cpp:66
ChatWindowStyleManager::StyleInstallOk
Definition: kopetechatwindowstylemanager.h:58
kopetechatwindowstylemanager.h
EmoticonThemeItem
Definition: emoticonthemeitem.h:25
QByteArray
ChatWindowStyleManager::StyleNoDirectoryValid
Definition: kopetechatwindowstylemanager.h:58
QSizePolicy
KopeteChatWindowSettings
Definition: kopetechatwindowsettings.h:13
ChatWindowStyleManager::StyleNotValid
Definition: kopetechatwindowstylemanager.h:58
kopetechatwindowstyle.h
manager
virtual Kopete::ChatSession * manager(Kopete::Contact::CanCreateFlags)
Definition: chatwindowconfig.cpp:94
ChatMessagePart
Definition: chatmessagepart.h:44
KopeteChatWindowSettings::setStyleName
static void setStyleName(const QString &v)
Set Name of a Adium/Kopete chat window style.
Definition: kopetechatwindowsettings.h:32
ChatWindowStyleManager::installStyle
int installStyle(const QString &styleBundlePath)
Install a new style into user style directory Note that you must pass a path to a archive...
Definition: kopetechatwindowstylemanager.cpp:112
QListWidgetItem
KopeteChatWindowSettings::self
static KopeteChatWindowSettings * self()
Definition: kopetechatwindowsettings.cpp:17
ChatMessagePart::setStyle
void setStyle(const QString &styleName)
Change the current style.
Definition: chatmessagepart.cpp:419
QTabWidget
Kopete::Items::MetaContact
Definition: kopeteitembase.h:57
ChatWindowStyleManager::StyleCannotOpen
Definition: kopetechatwindowstylemanager.h:58
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
kopetechatwindowsettings.h
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QHash::constEnd
const_iterator constEnd() const
QList::empty
bool empty() const
QObject
QString::isEmpty
bool isEmpty() const
QTabWidget::addTab
int addTab(QWidget *page, const QString &label)
ChatWindowConfig::load
virtual void load()
Definition: chatwindowconfig.cpp:286
QVBoxLayout
ChatWindowConfig::save
virtual void save()
Definition: chatwindowconfig.cpp:249
QList::first
T & first()
QString
QList
QColor
ChatWindowStyleManager::getStyleFromPool
ChatWindowStyle * getStyleFromPool(const QString &styleName)
Get a instance of a ChatWindowStyle from the pool.
Definition: kopetechatwindowstylemanager.cpp:350
QLayout::setMargin
void setMargin(int margin)
emoticonthemeitem.h
QStringList
chatmessagepart.h
ChatWindowConfig::~ChatWindowConfig
~ChatWindowConfig()
Definition: chatwindowconfig.cpp:233
KopeteChatWindowSettings::styleVariant
static QString styleVariant()
Get Relative path to a CSS variant for the current style.
Definition: kopetechatwindowsettings.h:71
emoticonthemedelegate.h
K_PLUGIN_FACTORY
K_PLUGIN_FACTORY(KopeteChatWindowConfigFactory, registerPlugin< ChatWindowConfig >();) class FakeContact
Definition: chatwindowconfig.cpp:84
QHash::ConstIterator
typedef ConstIterator
QDir
QHash::constBegin
const_iterator constBegin() const
QLatin1String
KopeteChatWindowSettings::styleName
static QString styleName()
Get Name of a Adium/Kopete chat window style.
Definition: kopetechatwindowsettings.h:44
ChatWindowStyleManager::getAvailableStyles
QStringList getAvailableStyles() const
Get all available styles.
Definition: kopetechatwindowstylemanager.cpp:107
ChatWindowStyleManager::StyleUnknow
Definition: kopetechatwindowstylemanager.h:58
slotUserInfo
virtual void slotUserInfo()
Definition: chatwindowconfig.cpp:95
ChatWindowConfig::ChatWindowConfig
ChatWindowConfig(QWidget *parent, const QVariantList &args)
Definition: chatwindowconfig.cpp:145
KopeteChatWindowSettings::setChatFmtOverride
static void setChatFmtOverride(bool v)
Set Disable custom formatting set by users.
Definition: kopetechatwindowsettings.h:200
KCModule
QListWidgetItem::text
QString text() const
chatwindowconfig.h
EmoticonThemeDelegate
Definition: emoticonthemedelegate.h:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal