diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/ui | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/libkopete/ui')
50 files changed, 7019 insertions, 0 deletions
diff --git a/kopete/libkopete/ui/Makefile.am b/kopete/libkopete/ui/Makefile.am new file mode 100644 index 00000000..211e0b48 --- /dev/null +++ b/kopete/libkopete/ui/Makefile.am @@ -0,0 +1,31 @@ +METASOURCES = AUTO +AM_CPPFLAGS = -DKDE_NO_COMPAT -DQT_NO_COMPAT -DQT_NO_CAST_ASCII -DQT_NO_ASCII_CAST \ + $(KOPETE_INCLUDES) -I$(top_srcdir)/kopete/libkopete/private $(all_includes) + +noinst_LTLIBRARIES = libkopeteui.la + +libkopeteui_la_SOURCES = kopetecontactaction.cpp addcontactpage.cpp \ + editaccountwidget.cpp kopetepassworddialog.ui kopetestdaction.cpp kopeteawaydialogbase.ui \ + kopetefileconfirmdialog.cpp fileconfirmbase.ui userinfodialog.cpp kopeteview.cpp \ + kopetepasswordwidgetbase.ui kopetepasswordwidget.cpp accountselector.cpp kopeteviewplugin.cpp \ + addresseeitem.cpp addressbookselectorwidget_base.ui addressbookselectordialog.cpp \ + addressbookselectorwidget.cpp metacontactselectorwidget_base.ui metacontactselectorwidget.cpp \ + kopetelistview.cpp kopetelistviewitem.cpp kopetelistviewsearchline.cpp \ + contactaddednotifywidget.ui contactaddednotifydialog.cpp addressbooklinkwidget_base.ui \ + addressbooklinkwidget.cpp + +libkopeteui_la_LDFLAGS = $(all_libraries) -lkabc +libkopeteui_la_LIBADD = ../private/libkopeteprivate.la $(LIB_KHTML) + +kopeteincludedir = $(includedir)/kopete/ui +kopeteinclude_HEADERS = accountselector.h fileconfirmbase.h \ + kopetefileconfirmdialog.h kopetepasswordwidget.h kopeteview.h addcontactpage.h \ + kopeteawaydialogbase.h kopetepasswordwidgetbase.h kopeteviewplugin.h editaccountwidget.h \ + kopetecontactaction.h kopetepassworddialog.h kopetestdaction.h userinfodialog.h \ + addressbookselectordialog.h addressbookselectorwidget.h kopetelistview.h kopetelistviewitem.h \ + kopetelistviewsearchline.h addressbooklinkwidget.h + +noinst_HEADERS = addresseeitem.h contactaddednotifywidget.h + +# vim: set noet: + diff --git a/kopete/libkopete/ui/accountselector.cpp b/kopete/libkopete/ui/accountselector.cpp new file mode 100644 index 00000000..2ea8e719 --- /dev/null +++ b/kopete/libkopete/ui/accountselector.cpp @@ -0,0 +1,186 @@ +/* + accountselector.cpp - An Accountselector + + Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "accountselector.h" +#include "kopeteaccount.h" +#include "kopeteaccountmanager.h" + +#include <qheader.h> +#include <qlayout.h> +#include <qpixmap.h> + +#include <kdebug.h> +#include <klistview.h> + +class AccountListViewItem : public KListViewItem +{ + private: + Kopete::Account *mAccount; + + public: + AccountListViewItem(QListView *parent, Kopete::Account *acc) + : KListViewItem(parent) + { + if (acc==0) + return; + + /*kdDebug(14010) << k_funcinfo << + "account name = " << acc->accountId() << endl;*/ + mAccount = acc; + setText(0, mAccount->accountId()); + setPixmap(0, mAccount->accountIcon()); + } + + Kopete::Account *account() + { + return mAccount; + } +}; + + +// ---------------------------------------------------------------------------- + +class AccountSelectorPrivate +{ + public: + KListView *lv; + Kopete::Protocol *proto; +}; + + +AccountSelector::AccountSelector(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + //kdDebug(14010) << k_funcinfo << "for no special protocol" << endl; + d = new AccountSelectorPrivate; + d->proto = 0; + initUI(); +} + + +AccountSelector::AccountSelector(Kopete::Protocol *proto, QWidget *parent, + const char *name) : QWidget(parent, name) +{ + //kdDebug(14010) << k_funcinfo << " for protocol " << proto->pluginId() << endl; + d = new AccountSelectorPrivate; + d->proto = proto; + initUI(); +} + + +AccountSelector::~AccountSelector() +{ + kdDebug(14010) << k_funcinfo << endl; + delete d; +} + + +void AccountSelector::initUI() +{ + kdDebug(14010) << k_funcinfo << endl; + (new QVBoxLayout(this))->setAutoAdd(true); + d->lv = new KListView(this); + d->lv->setFullWidth(true); + d->lv->addColumn(QString::fromLatin1("")); + d->lv->header()->hide(); + + if(d->proto != 0) + { + kdDebug(14010) << k_funcinfo << "creating list for a certain protocol" << endl; + QDict<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts(d->proto); + QDictIterator<Kopete::Account> it(accounts); + for(; Kopete::Account *account = it.current(); ++it) + { + new AccountListViewItem(d->lv, account); + } + } + else + { + kdDebug(14010) << k_funcinfo << "creating list of all accounts" << endl; + QPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts(); + Kopete::Account *account = 0; + for(account = accounts.first(); account; account = accounts.next()) + { + new AccountListViewItem(d->lv, account); + } + } + + connect(d->lv, SIGNAL(selectionChanged(QListViewItem *)), + this, SLOT(slotSelectionChanged(QListViewItem *))); +} + + +void AccountSelector::setSelected(Kopete::Account *account) +{ + if (account==0) + return; + + QListViewItemIterator it(d->lv); + while (it.current()) + { + if(static_cast<AccountListViewItem *>(it.current())->account() == account) + { + it.current()->setSelected(true); + return; + } + } +} + + +bool AccountSelector::isSelected(Kopete::Account *account) +{ + if (account==0) + return false; + + QListViewItemIterator it(d->lv); + while (it.current()) + { + if(static_cast<AccountListViewItem *>(it.current())->account() == account) + return true; + } + return false; +} + + +Kopete::Account *AccountSelector::selectedItem() +{ + //kdDebug(14010) << k_funcinfo << endl; + + if (d->lv->selectedItem() != 0) + return static_cast<AccountListViewItem *>(d->lv->selectedItem())->account(); + return 0; +} + + +void AccountSelector::slotSelectionChanged(QListViewItem *item) +{ + //kdDebug(14010) << k_funcinfo << endl; + if (item != 0) + { + Kopete::Account *account = static_cast<AccountListViewItem *>(item)->account(); + if (account != 0) + { + emit selectionChanged(account); + return; + } + } + + emit selectionChanged(0); +} + +#include "accountselector.moc" +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/accountselector.h b/kopete/libkopete/ui/accountselector.h new file mode 100644 index 00000000..4f5d50ac --- /dev/null +++ b/kopete/libkopete/ui/accountselector.h @@ -0,0 +1,92 @@ +/* + accountselector.cpp - An Accountselector + + Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef ACCOUNTSELECTOR_H +#define ACCOUNTSELECTOR_H + +#include <qwidget.h> +#include <kopeteprotocol.h> +#include "kopete_export.h" + +class AccountSelectorPrivate; +class QListViewItem; +/** + * \brief widget to select an account, based on KListView + * @author Stefan Gehn <metz AT gehn.net> + */ +class KOPETE_EXPORT AccountSelector : public QWidget +{ +Q_OBJECT + + public: + /** + * Constructor. + * + * The parameters @p parent and @p name are handled by + * KListView. + */ + AccountSelector(QWidget *parent=0, const char *name=0); + + /** + * Constructor for a list of accounts for one protocol only + * + * The parameters @p parent and @p name are handled by + * KListView. @p proto defines the protocol whose accounts are + * shown in the list + */ + AccountSelector(Kopete::Protocol *proto, QWidget *parent=0, const char *name=0); + + /** + * Destructor. + */ + ~AccountSelector(); + + /** + * Select @p account in the list, in case it's part of the list + */ + void setSelected(Kopete::Account *account); + + /** + * Returns true in case @p account is in the list and + * the currently selected item, false otherwise + */ + bool isSelected(Kopete::Account *account); + + /** + * @return the currently selected account. + */ + Kopete::Account *selectedItem(); + + signals: + /** + * Emitted whenever the selection changed, @p acc is a pointer to the + * newly selected account + */ + void selectionChanged(Kopete::Account *acc); + + private slots: + void slotSelectionChanged(QListViewItem *item); + + private: + void initUI(); + + private: + AccountSelectorPrivate *d; +}; + +#endif +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addcontactpage.cpp b/kopete/libkopete/ui/addcontactpage.cpp new file mode 100644 index 00000000..f308a7d4 --- /dev/null +++ b/kopete/libkopete/ui/addcontactpage.cpp @@ -0,0 +1,29 @@ +/* + addcontactpage.cpp - Kopete's Add Contact GUI + + Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "addcontactpage.h" + +AddContactPage::AddContactPage(QWidget *parent, const char *name ) : QWidget(parent,name) +{ +} + +AddContactPage::~AddContactPage() +{ +} + +#include "addcontactpage.moc" +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addcontactpage.h b/kopete/libkopete/ui/addcontactpage.h new file mode 100644 index 00000000..506c5bcc --- /dev/null +++ b/kopete/libkopete/ui/addcontactpage.h @@ -0,0 +1,65 @@ +/* + addcontactpage.h - Kopete's Add Contact GUI + + Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef ADDCONTACTPAGE_H +#define ADDCONTACTPAGE_H + +#include <qwidget.h> +#include <kopeteprotocol.h> + +#include "kopete_export.h" + +/** + * @author Duncan Mac-Vicar P. <duncan@kde.org> + * @todo i want to be able to have a assync apply. + * (in the case of jabber, i need to translate the legacy id to a JID) + * this could also be usefull in the case of MLSN to check if no error (and also jabber) + */ +class KOPETE_EXPORT AddContactPage : public QWidget +{ +Q_OBJECT + +public: + AddContactPage(QWidget *parent=0, const char *name=0); + virtual ~AddContactPage(); + //Kopete::Protocol *protocol; + + /** + * Plugin should reimplement this methode. + * return true if the content of the page are valid + * + * This method is called in the add account wizzard when the user press the next button + * and this page is showed. when it return false, it does not go to the nextpage. + * You should popup a dialog to explain WHY the page has not been validate + */ + virtual bool validateData()=0; + + /** + * add the contact the the specified meta contact, with the given account + * return false if the contact has not been added + */ + virtual bool apply(Kopete::Account * , Kopete::MetaContact *) = 0; + +signals: + /** + * New incarnation of validateData, emit it everytime you think the current data is valid/invalid + */ + void dataValid( AddContactPage *, bool); +}; + +#endif +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addressbooklinkwidget.cpp b/kopete/libkopete/ui/addressbooklinkwidget.cpp new file mode 100644 index 00000000..a6aff32b --- /dev/null +++ b/kopete/libkopete/ui/addressbooklinkwidget.cpp @@ -0,0 +1,99 @@ +/* + AddressBookLinkWidget + + A compact widget for showing and changing which address book item a + particular Kopete::MetaContact is related to. + + Comprises a label showing the contact's name, a Clear button, and a Change + button that usually invokes the AddressBookSelectorWidget. + + Copyright (c) 2006 by Will Stephenson <wstephenson@kde.org> + + Kopete (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qapplication.h> +#include <klineedit.h> +#include <klocale.h> +#include <kpushbutton.h> + +#include <kiconloader.h> + +#include <kopetemetacontact.h> + +#include "addressbooklinkwidget.h" +#include "addressbookselectordialog.h" +#include "addressbookselectorwidget.h" + +namespace Kopete { +namespace UI { + + +AddressBookLinkWidget::AddressBookLinkWidget( QWidget * parent, const char * name ) : AddressBookLinkWidgetBase( parent, name ), mMetaContact( 0 ) +{ + btnClear->setIconSet( SmallIconSet( QApplication::reverseLayout() ? QString::fromLatin1( "locationbar_erase" ) : QString::fromLatin1( "clear_left") ) ); + connect( btnClear, SIGNAL( clicked() ), this, SLOT( slotClearAddressee() ) ); + connect( btnSelectAddressee, SIGNAL( clicked() ), SLOT( slotSelectAddressee() ) ); +} + +void AddressBookLinkWidget::setAddressee( const KABC::Addressee& addr ) +{ + edtAddressee->setText( addr.realName() ); + btnClear->setEnabled( !addr.isEmpty() ); +} + +void AddressBookLinkWidget::setMetaContact( const Kopete::MetaContact * mc ) +{ + mMetaContact = mc; +} + +QString AddressBookLinkWidget::uid() const +{ + return mSelectedUid; +} + +void AddressBookLinkWidget::slotClearAddressee() +{ + edtAddressee->clear(); + btnClear->setEnabled( false ); + KABC::Addressee mrEmpty; + mSelectedUid = QString::null; + emit addresseeChanged( mrEmpty ); +} + +void AddressBookLinkWidget::slotSelectAddressee() +{ + QString message; + if ( mMetaContact ) + message = i18n("Choose the corresponding entry for '%1'" ).arg( mMetaContact->displayName() ); + else + message = i18n("Choose the corresponding entry in the address book" ); + + Kopete::UI::AddressBookSelectorDialog dialog( i18n("Addressbook Association"), message, ( mMetaContact ? mMetaContact->metaContactId() : QString::null ), this ); + int result = dialog.exec(); + + KABC::Addressee addr; + if ( result == QDialog::Accepted ) + { + addr = dialog.addressBookSelectorWidget()->addressee(); + + edtAddressee->setText( addr.realName() ); + btnClear->setEnabled( !addr.isEmpty() ); + mSelectedUid = ( addr.isEmpty() ? QString::null : addr.uid() ); + emit addresseeChanged( addr ); + } +} + +} // end namespace UI +} // end namespace Kopete + +#include "addressbooklinkwidget.moc" diff --git a/kopete/libkopete/ui/addressbooklinkwidget.h b/kopete/libkopete/ui/addressbooklinkwidget.h new file mode 100644 index 00000000..dff23c58 --- /dev/null +++ b/kopete/libkopete/ui/addressbooklinkwidget.h @@ -0,0 +1,81 @@ +/* + AddressBookLinkWidget + + A compact widget for showing and changing which address book item a + particular Kopete::MetaContact is related to. + + Comprises a label showing the contact's name, a Clear button, and a Change + button that usually invokes the AddressBookSelectorWidget. + + Copyright (c) 2006 by Will Stephenson <wstephenson@kde.org> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef ADDRESSBOOKLINKWIDGET_H +#define ADDRESSBOOKLINKWIDGET_H + +#include <kabc/addressee.h> + +#include "addressbooklinkwidget_base.h" + +namespace Kopete { +class MetaContact; + +namespace UI { + +/** + * A compact widget for showing and changing which address book item a + * particular Kopete::MetaContact is related to. + * + * Comprises a label showing the contact's name, a Clear button, and a Change + * button that usually invokes the AddressBookSelectorWidget. + */ +class AddressBookLinkWidget : public AddressBookLinkWidgetBase +{ +Q_OBJECT +public: + AddressBookLinkWidget( QWidget * parent, const char * name ); + ~AddressBookLinkWidget() {} + /** + * Set the currently selected addressee + */ + void setAddressee( const KABC::Addressee& addr ); + /** + * Set the current metacontact so that the selector dialog may be preselected + */ + void setMetaContact( const Kopete::MetaContact * ); + /** + * Return the selected addressbook UID. + */ + QString uid() const; +signals: + /** + * Emitted when the selected addressee changed. addr is the KABC::Addressee that was selected. If addr.isEmpty() is empty, the clear button was clicked. + */ + void addresseeChanged( const KABC::Addressee& addr ); + + /** + * Provided so you can perform your own actions instead of opening the AddressBookSelectorWidget. + * To do so, QObject::disconnect() btnSelectAddressee and connect your own slot to this signal + */ + void selectAddresseeClicked(); +protected slots: + void slotClearAddressee(); + void slotSelectAddressee(); +private: + const Kopete::MetaContact * mMetaContact; + QString mSelectedUid; +}; +} // end namespace UI +} // end namespace Kopete +#endif diff --git a/kopete/libkopete/ui/addressbooklinkwidget_base.ui b/kopete/libkopete/ui/addressbooklinkwidget_base.ui new file mode 100644 index 00000000..4656459c --- /dev/null +++ b/kopete/libkopete/ui/addressbooklinkwidget_base.ui @@ -0,0 +1,78 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AddressBookLinkWidgetBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AddressBookLinkWidgetBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>350</width> + <height>31</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KLineEdit"> + <property name="name"> + <cstring>edtAddressee</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>The KDE Address Book entry associated with this Kopete Contact</string> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>btnClear</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="toolTip" stdset="0"> + <string>Clear</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>btnSelectAddressee</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>C&hange...</string> + </property> + <property name="toolTip" stdset="0"> + <string>Select an address book entry</string> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/addressbookselectordialog.cpp b/kopete/libkopete/ui/addressbookselectordialog.cpp new file mode 100644 index 00000000..7d2e17ff --- /dev/null +++ b/kopete/libkopete/ui/addressbookselectordialog.cpp @@ -0,0 +1,89 @@ +/* + AddressBookSelectorDialog + Nice Dialog to select a KDE AddressBook contact + + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "addressbookselectordialog.h" +#include "addressbookselectorwidget.h" +#include <kdialogbase.h> +#include <qdialog.h> +#include <qlistview.h> +#include <qvbox.h> +#include <klocale.h> +#include <kdialog.h> + +namespace Kopete +{ +namespace UI +{ + +AddressBookSelectorDialog::AddressBookSelectorDialog(const QString &title, const QString &message, const QString &preSelectUid, QWidget *parent, const char *name, bool modal ) : KDialogBase(parent, name, modal, title, Help|Ok|Cancel, Ok, true ) +{ + QVBox *vbox=new QVBox(this); + m_addressBookSelectorWidget= new AddressBookSelectorWidget(vbox); + m_addressBookSelectorWidget->setLabelMessage(message); + + vbox->setSpacing( KDialog::spacingHint() ); + + setMainWidget(vbox); + enableButtonOK(false); + //setHelp("linkaddressbook"); + + connect(m_addressBookSelectorWidget, SIGNAL(addresseeListClicked( QListViewItem * )), SLOT(slotWidgetAddresseeListClicked( QListViewItem * ))); + + if ( !preSelectUid.isEmpty() ) + m_addressBookSelectorWidget->selectAddressee(preSelectUid); +} + +AddressBookSelectorDialog::~AddressBookSelectorDialog() +{ +} + +KABC::Addressee AddressBookSelectorDialog::getAddressee( const QString &title, const QString &message, const QString &preSelectUid, QWidget *parent) +{ + AddressBookSelectorDialog dialog(title, message, preSelectUid, parent); + int result = dialog.exec(); + + KABC::Addressee adr; + if ( result == QDialog::Accepted ) + adr = dialog.addressBookSelectorWidget()->addressee(); + + return adr; +} + +void AddressBookSelectorDialog::slotWidgetAddresseeListClicked( QListViewItem *addressee ) +{ + // enable ok if a valid addressee is selected + enableButtonOK( addressee ? addressee->isSelected() : false); +} + +void AddressBookSelectorDialog::accept() +{ + QDialog::accept(); +} + +void AddressBookSelectorDialog::reject() +{ + QDialog::reject(); +} + +} // namespace UI +} // namespace Kopete + +#include "addressbookselectordialog.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbookselectordialog.h b/kopete/libkopete/ui/addressbookselectordialog.h new file mode 100644 index 00000000..f391aa3a --- /dev/null +++ b/kopete/libkopete/ui/addressbookselectordialog.h @@ -0,0 +1,90 @@ +/* + AddressBookSelectorDialog + Nice Dialog to select a KDE AddressBook contact + + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef ADDRESSBOOKSELECTORDIALOG_H +#define ADDRESSBOOKSELECTORDIALOG_H + +#include <kdemacros.h> +#include "kopete_export.h" +#include <kdialogbase.h> + +namespace KABC +{ + class AddressBook; + class Addressee; +} + +namespace Kopete +{ +namespace UI +{ + +class AddressBookSelectorWidget; + +/** + * A dialog that uses AddressBookSelectorWidget to allow the user + * to select a KDE addressbook contact. If you want to use special features + * you can use @see addressBookSelectorWidget() to get the pointer to the + * AddressBookSelectorWidget object and set the desired options there. + * + * @author Duncan Mac-Vicar Prett <duncan@kde.org> + */ +class KOPETE_EXPORT AddressBookSelectorDialog : public KDialogBase +{ + Q_OBJECT +public: + /** + * The constructor of an empty AddressBookSelectorWidget + */ + AddressBookSelectorDialog( const QString &title, const QString &message, const QString &preSelectUid, QWidget *parent=0L, const char *name=0L, bool modal = false ); + /** + * The destructor of the dialog + */ + ~AddressBookSelectorDialog(); + + /** + * @returns the AddressBookSelectorWidget widget so that additional + * parameters can be set by using it. + */ + AddressBookSelectorWidget *addressBookSelectorWidget() const + { return m_addressBookSelectorWidget; }; + + /** + * Creates a modal dialog, lets the user to select a addressbook contact + * and returns when the dialog is closed. + * + * @returns the selected contact, or a null addressee if the user + * pressed the Cancel button. Optionally + */ + static KABC::Addressee getAddressee( const QString &title, const QString &message, const QString &preSelectUid, QWidget *parent = 0L ); + +protected slots: + virtual void accept(); + virtual void reject(); + void slotWidgetAddresseeListClicked( QListViewItem *addressee ); +protected: + AddressBookSelectorWidget *m_addressBookSelectorWidget; +}; + +} // namespace UI +} // namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbookselectorwidget.cpp b/kopete/libkopete/ui/addressbookselectorwidget.cpp new file mode 100644 index 00000000..50c4a885 --- /dev/null +++ b/kopete/libkopete/ui/addressbookselectorwidget.cpp @@ -0,0 +1,171 @@ +/* + AddressBookSelectorWidget + + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Based on LinkAddressBookUI whose code was shamelessly stolen from + kopete's add new contact wizard, used in Konversation, and then + reappropriated by Kopete. + + LinkAddressBookUI: + Copyright (c) 2004 by John Tapsell <john@geola.co.uk> + Copyright (c) 2003-2005 by Will Stephenson <will@stevello.free-online.co.uk> + Copyright (c) 2002 by Nick Betcher <nbetcher@kde.org> + Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qcheckbox.h> +#include <kapplication.h> +#include <kconfig.h> +#include <klocale.h> +#include <kiconloader.h> + +#include <kdeversion.h> +#include <kinputdialog.h> + +#include <kpushbutton.h> +#include <kactivelabel.h> +#include <kdebug.h> +#include <klistview.h> +#include <klistviewsearchline.h> +#include <qlabel.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +#include "addressbookselectorwidget.h" +#include <addresseeitem.h> +#include "kabcpersistence.h" + +using namespace Kopete::UI; + +namespace Kopete +{ +namespace UI +{ + +AddressBookSelectorWidget::AddressBookSelectorWidget( QWidget *parent, const char *name ) + : AddressBookSelectorWidget_Base( parent, name ) +{ + m_addressBook = Kopete::KABCPersistence::self()->addressBook(); + + // Addressee validation connections + connect( addAddresseeButton, SIGNAL( clicked() ), SLOT( slotAddAddresseeClicked() ) ); + connect( addAddresseeButton, SIGNAL( clicked() ), SIGNAL( addAddresseeClicked() ) ); + + connect( addresseeListView, SIGNAL( clicked(QListViewItem * ) ), + SIGNAL( addresseeListClicked( QListViewItem * ) ) ); + connect( addresseeListView, SIGNAL( selectionChanged( QListViewItem * ) ), + SIGNAL( addresseeListClicked( QListViewItem * ) ) ); + connect( addresseeListView, SIGNAL( spacePressed( QListViewItem * ) ), + SIGNAL( addresseeListClicked( QListViewItem * ) ) ); + + connect( m_addressBook, SIGNAL( addressBookChanged( AddressBook * ) ), this, SLOT( slotLoadAddressees() ) ); + + //We should add a clear KAction here. But we can't really do that with a designer file :\ this sucks + + addresseeListView->setColumnText(2, SmallIconSet(QString::fromLatin1("email")), i18n("Email")); + + kListViewSearchLine->setListView(addresseeListView); + slotLoadAddressees(); + + addresseeListView->setColumnWidthMode(0, QListView::Manual); + addresseeListView->setColumnWidth(0, 63); //Photo is 60, and it's nice to have a small gap, imho +} + + +AddressBookSelectorWidget::~AddressBookSelectorWidget() +{ + disconnect( m_addressBook, SIGNAL( addressBookChanged( AddressBook * ) ), this, SLOT( slotLoadAddressees() ) ); +} + + +KABC::Addressee AddressBookSelectorWidget::addressee() +{ + AddresseeItem *item = 0L; + item = static_cast<AddresseeItem *>( addresseeListView->selectedItem() ); + + if ( item ) + m_addressee = item->addressee(); + + return m_addressee; +} + +void AddressBookSelectorWidget::selectAddressee( const QString &uid ) +{ + // iterate trough list view + QListViewItemIterator it( addresseeListView ); + while( it.current() ) + { + AddresseeItem *addrItem = (AddresseeItem *) it.current(); + if ( addrItem->addressee().uid() == uid ) + { + // select the contact item + addresseeListView->setSelected( addrItem, true ); + addresseeListView->ensureItemVisible( addrItem ); + } + ++it; + } +} + +bool AddressBookSelectorWidget::addresseeSelected() +{ + return addresseeListView->selectedItem() ? true : false; +} + +/** Read in contacts from addressbook, and select the contact that is for our nick. */ +void AddressBookSelectorWidget::slotLoadAddressees() +{ + addresseeListView->clear(); + KABC::AddressBook::Iterator it; + AddresseeItem *addr; + for( it = m_addressBook->begin(); it != m_addressBook->end(); ++it ) + { + addr = new AddresseeItem( addresseeListView, (*it)); + } + +} + +void AddressBookSelectorWidget::setLabelMessage( const QString &msg ) +{ + lblHeader->setText(msg); +} + +void AddressBookSelectorWidget::slotAddAddresseeClicked() +{ + // Pop up add addressee dialog + QString addresseeName = KInputDialog::getText( i18n( "New Address Book Entry" ), i18n( "Name the new entry:" ), QString::null, 0, this ); + + if ( !addresseeName.isEmpty() ) + { + KABC::Addressee addr; + addr.setNameFromString( addresseeName ); + m_addressBook->insertAddressee(addr); + Kopete::KABCPersistence::self()->writeAddressBook( 0 ); + slotLoadAddressees(); + // select the addressee we just added + QListViewItem * added = addresseeListView->findItem( addresseeName, 1 ); + kListViewSearchLine->clear(); + kListViewSearchLine->updateSearch(); + addresseeListView->setSelected( added, true ); + addresseeListView->ensureItemVisible( added ); + } +} + +} // namespace UI +} // namespace Kopete + +#include "addressbookselectorwidget.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbookselectorwidget.h b/kopete/libkopete/ui/addressbookselectorwidget.h new file mode 100644 index 00000000..3141f726 --- /dev/null +++ b/kopete/libkopete/ui/addressbookselectorwidget.h @@ -0,0 +1,90 @@ +/* + AddressBookSelectorWidget + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Based on LinkAddressBookUI whose code was shamelessly stolen from + kopete's add new contact wizard, used in Konversation, and then + reappropriated by Kopete. + + LinkAddressBookUI: + Copyright (c) 2004 by John Tapsell <john@geola.co.uk> + Copyright (c) 2003-2005 by Will Stephenson <will@stevello.free-online.co.uk> + Copyright (c) 2002 by Nick Betcher <nbetcher@kde.org> + Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef AddressBookSelectorWidget_H +#define AddressBookSelectorWidget_H + +#include <kdialogbase.h> +#include <kabc/addressbook.h> + +#include <kdemacros.h> +#include "kopete_export.h" + +#include "addressbookselectorwidget_base.h" + +namespace KABC { + class AddressBook; + class Addressee; +} + +namespace Kopete +{ +namespace UI +{ + +class KOPETE_EXPORT AddressBookSelectorWidget : public AddressBookSelectorWidget_Base +{ + Q_OBJECT +public: + AddressBookSelectorWidget( QWidget *parent = 0, const char *name = 0 ); + ~AddressBookSelectorWidget(); + KABC::Addressee addressee(); + /** + * sets the widget label message + * example: Please select a contact + * or, Choose a contact to delete + */ + void setLabelMessage( const QString &msg ); + /** + * pre-selects a contact + */ + void selectAddressee( const QString &uid ); + /** + * @return true if there is a contact selected + */ + bool addresseeSelected(); + +private: + KABC::AddressBook * m_addressBook; + KABC::Addressee m_addressee; + +protected slots: + void slotAddAddresseeClicked(); + /** + * Utility function, populates the addressee list + */ + void slotLoadAddressees(); +signals: + void addresseeListClicked( QListViewItem *addressee ); + void addAddresseeClicked(); +}; + +} // namespace UI +} // namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addressbookselectorwidget_base.ui b/kopete/libkopete/ui/addressbookselectorwidget_base.ui new file mode 100644 index 00000000..d5e2e6f2 --- /dev/null +++ b/kopete/libkopete/ui/addressbookselectorwidget_base.ui @@ -0,0 +1,175 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AddressBookSelectorWidget_Base</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AddressBookSelectorWidget_Base</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>596</width> + <height>572</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>Select Contact</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <spacer row="3" column="1"> + <property name="name"> + <cstring>spacer11</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>405</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="3" column="0"> + <property name="name"> + <cstring>addAddresseeButton</cstring> + </property> + <property name="text"> + <string>Create New Entr&y...</string> + </property> + <property name="toolTip" stdset="0"> + <string>Create a new entry in your address book</string> + </property> + </widget> + <widget class="KActiveLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>lblHeader</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>4</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KListView" row="2" column="0" rowspan="1" colspan="2"> + <column> + <property name="text"> + <string>Photo</string> + </property> + <property name="clickable"> + <bool>false</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Email</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>addresseeListView</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>10</verstretch> + </sizepolicy> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + <property name="resizeMode"> + <enum>LastColumn</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Select the contact you want to communicate with via Instant Messaging</string> + </property> + </widget> + <widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lblSearch</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>S&earch:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kListViewSearchLine</cstring> + </property> + </widget> + <widget class="KListViewSearchLine"> + <property name="name"> + <cstring>kListViewSearchLine</cstring> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<includes> + <include location="global" impldecl="in declaration">klistviewsearchline.h</include> +</includes> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +<includehints> + <includehint>kactivelabel.h</includehint> + <includehint>klistview.h</includehint> + <includehint>klistviewsearchline.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/addresseeitem.cpp b/kopete/libkopete/ui/addresseeitem.cpp new file mode 100644 index 00000000..3888ee27 --- /dev/null +++ b/kopete/libkopete/ui/addresseeitem.cpp @@ -0,0 +1,63 @@ +/* + Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <qlayout.h> +#include <qpushbutton.h> +#include <qgroupbox.h> +#include <qregexp.h> + +#include <klocale.h> +#include <kdebug.h> + +#include "addresseeitem.h" + +AddresseeItem::AddresseeItem( QListView *parent, const KABC::Addressee &addressee) : + KListViewItem( parent ), + mAddressee( addressee ) +{ + //We can't save showphoto because we don't have a d pointer + KABC::Picture pic = mAddressee.photo(); + if(!pic.isIntern()) + pic = mAddressee.logo(); + if(pic.isIntern()) + { + QPixmap qpixmap( pic.data().scaleWidth(60) ); //60 pixels seems okay.. kmail uses 60 btw + setPixmap( Photo,qpixmap ); + } + + setText( Name, addressee.realName() ); + setText( Email, addressee.preferredEmail() ); +} + +QString AddresseeItem::key( int column, bool ) const +{ + if (column == Email) { + QString value = text(Email); + QRegExp emailRe(QString::fromLatin1("<\\S*>")); + int match = emailRe.search(value); + if (match > -1) + value = value.mid(match + 1, emailRe.matchedLength() - 2); + + return value.lower(); + } + + return text(column).lower(); +} + + diff --git a/kopete/libkopete/ui/addresseeitem.h b/kopete/libkopete/ui/addresseeitem.h new file mode 100644 index 00000000..b190fea6 --- /dev/null +++ b/kopete/libkopete/ui/addresseeitem.h @@ -0,0 +1,68 @@ +/* + This file is part of libkabc. + Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef KABC_ADDRESSEEDIALOG_H +#define KABC_ADDRESSEEDIALOG_H + +#include <qdict.h> + +#include <kdialogbase.h> +#include <klineedit.h> +#include <klistview.h> + +#include <kabc/addressbook.h> + +/** + @short Special ListViewItem +*/ +class AddresseeItem : public KListViewItem +{ + public: + + /** + Type of column + @li @p Name - Name in Addressee + @li @p Email - Email in Addressee + */ + enum columns { Photo =0, Name = 1, Email = 2 }; + + /** + Constructor. + + @param parent The parent listview. + @param addressee The associated addressee. + */ + AddresseeItem( QListView *parent, const KABC::Addressee &addressee ); + + /** + Returns the addressee. + */ + KABC::Addressee addressee() const { return mAddressee; } + + /** + Method used by QListView to sort the items. + */ + virtual QString key( int column, bool ascending ) const; + + private: + KABC::Addressee mAddressee; +}; + +#endif diff --git a/kopete/libkopete/ui/contactaddednotifydialog.cpp b/kopete/libkopete/ui/contactaddednotifydialog.cpp new file mode 100644 index 00000000..abcd4c7e --- /dev/null +++ b/kopete/libkopete/ui/contactaddednotifydialog.cpp @@ -0,0 +1,178 @@ +/* + Copyright (c) 2005 Olivier Goffart <ogoffart@ kde.org> + + Kopete (c) 2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "contactaddednotifydialog.h" + + +#include <qvbox.h> +#include <qlabel.h> +#include <qcheckbox.h> +#include <qgroupbox.h> +#include <qstylesheet.h> +#include <qapplication.h> + +#include <klocale.h> +#include <kcombobox.h> +#include <klineedit.h> +#include <kpushbutton.h> +#include <kiconloader.h> + +#include <kabc/addressee.h> + +#include "kopetegroup.h" +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" +#include "kopeteprotocol.h" +#include "kopetecontactlist.h" +#include "kopetemetacontact.h" +#include "addressbooklinkwidget.h" +#include "addressbookselectordialog.h" + + +#include "contactaddednotifywidget.h" + +namespace Kopete { + +namespace UI { + +struct ContactAddedNotifyDialog::Private +{ + ContactAddedNotifyWidget *widget; + Account *account; + QString contactId; + QString addressbookId; +}; + + +ContactAddedNotifyDialog::ContactAddedNotifyDialog(const QString& contactId, + const QString& contactNick, Kopete::Account *account, uint hide) + : KDialogBase( Global::mainWidget(), "ContactAddedNotify", /*modal=*/false, + i18n("Someone Has Added You"), Ok|Cancel ) +{ + + setWFlags(WDestructiveClose | getWFlags() ); + + d=new Private; + d->widget=new ContactAddedNotifyWidget(this); + setMainWidget(d->widget); + + d->account=account; + d->contactId=contactId; + d->widget->m_label->setText(i18n("<qt><img src=\"kopete-account-icon:%1\" /> The contact <b>%2</b> has added you to his/her contactlist. (Account %3)</qt>") + .arg( KURL::encode_string( account->protocol()->pluginId() ) + QString::fromLatin1(":") + + KURL::encode_string( account->accountId() ) , + contactNick.isEmpty() ? contactId : contactNick + QString::fromLatin1(" < ") + contactId + QString::fromLatin1(" >") , + account->accountLabel() ) ); + if( hide & InfoButton) + d->widget->m_infoButton->hide() ; + if( hide & AuthorizeCheckBox ) + { + d->widget->m_authorizeCb->hide(); + d->widget->m_authorizeCb->setChecked(false); + } + if( hide & AddCheckBox ) + { + d->widget->m_addCb->hide(); + d->widget->m_addCb->setChecked(false); + } + if( hide & AddGroupBox ) + d->widget->m_contactInfoBox->hide(); + + // Populate the groups list + Kopete::GroupList groups=Kopete::ContactList::self()->groups(); + for( Kopete::Group *it = groups.first(); it; it = groups.next() ) + { + QString groupname = it->displayName(); + if ( it->type() == Group::Normal && !groupname.isEmpty() ) + { + d->widget->m_groupList->insertItem(groupname); + } + } + d->widget->m_groupList->setCurrentText(QString::null); //default to top-level + + connect( d->widget->widAddresseeLink, SIGNAL( addresseeChanged( const KABC::Addressee& ) ), this, SLOT( slotAddresseeSelected( const KABC::Addressee& ) ) ); + connect( d->widget->m_infoButton, SIGNAL( clicked() ), this, SLOT( slotInfoClicked() ) ); + + connect( this, SIGNAL(okClicked()) , this , SLOT(slotFinished())); + +} + + +ContactAddedNotifyDialog::~ContactAddedNotifyDialog() +{ + delete d; +} + +bool ContactAddedNotifyDialog::added() const +{ + return d->widget->m_addCb->isChecked(); +} + +bool ContactAddedNotifyDialog::authorized() const +{ + return d->widget->m_authorizeCb->isChecked(); +} + +QString ContactAddedNotifyDialog::displayName() const +{ + return d->widget->m_displayNameEdit->text(); +} + +Group *ContactAddedNotifyDialog::group() const +{ + QString grpName=d->widget->m_groupList->currentText(); + if(grpName.isEmpty()) + return Group::topLevel(); + + return ContactList::self()->findGroup( grpName ); +} + +MetaContact *ContactAddedNotifyDialog::addContact() const +{ + if(!added() || !d->account) + return 0L; + + MetaContact *metacontact=d->account->addContact(d->contactId, displayName(), group()); + if(!metacontact) + return 0L; + + metacontact->setMetaContactId(d->addressbookId); + + return metacontact; +} + +void ContactAddedNotifyDialog::slotAddresseeSelected( const KABC::Addressee & addr ) +{ + if ( !addr.isEmpty() ) + { + d->addressbookId = addr.uid(); + } +} + +void ContactAddedNotifyDialog::slotInfoClicked() +{ + emit infoClicked(d->contactId); +} + +void ContactAddedNotifyDialog::slotFinished() +{ + emit applyClicked(d->contactId); +} + + + +} // namespace UI +} // namespace Kopete +#include "contactaddednotifydialog.moc" diff --git a/kopete/libkopete/ui/contactaddednotifydialog.h b/kopete/libkopete/ui/contactaddednotifydialog.h new file mode 100644 index 00000000..96f8844c --- /dev/null +++ b/kopete/libkopete/ui/contactaddednotifydialog.h @@ -0,0 +1,175 @@ +/* + Copyright (c) 2005 Olivier Goffart <ogoffart@ kde.org> + + Kopete (c) 2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + + +#ifndef KOPETE_UICONTACTADDEDNOTIFYDIALOG_H +#define KOPETE_UICONTACTADDEDNOTIFYDIALOG_H + +#include <kdialogbase.h> +#include "kopete_export.h" + +namespace KABC { + class Addressee; +} + +namespace Kopete { + +class Group; +class Account; +class MetaContact; + +namespace UI { + +/** + * @brief Dialog which is shown when a contact added you in the contactlist. + * + * This dialog asks the user to give authorization for the addition to the + * person who added the user and also asks the user if the contact who you've + * received the notification for should be added to the user's contact list + * + * example of usage + * @code + + Kopete::UI::ContactAddedNotifyDialog *dialog = + new ContactAddedNotifyDialog(contactId, QString::null,account); + QObject::connect(dialog,SIGNAL(applyClicked(const QString&)),this,SLOT(contactAddedDialogApplied())); + QObject::connect(dialog,SIGNAL(infoClicked(const QString&)),this,SLOT(contactAddedDialogInfo())); + dialog->show(); + + * @endcode + * + * and in your contactAddedDialogApplied slot + * @code + const Kopete::UI::ContactAddedNotifyDialog *dialog = + dynamic_cast<const Kopete::UI::ContactAddedNotifyDialog *>(sender()); + if(!dialog) + return; + if(dialog->authorized()) + socket->authorize(contactId); + if(dialog->added()) + dialog->addContact(); + * @endcode + * + * Note that you can also use exec() but this is not recommended + * + * @author Olivier Goffart + * @since 0.11 + */ +class KOPETE_EXPORT ContactAddedNotifyDialog : public KDialogBase +{ +Q_OBJECT +public: + /** + * All widget in the dialog that may be hidden. + */ + enum HideWidget + { + InfoButton = 0x01, /**< the button which ask for more info about the contact */ + AuthorizeCheckBox = 0x02, /**< the checkbox which ask for authorize the contact */ + AddCheckBox = 0x04, /**< the checkbox which ask if the contact should be added */ + AddGroupBox = 0x08 /**< all the widget about metacontact properties */ + }; + + /** + * @brief Constructor + * + * The dialog is by default not modal, and will delete itself when closed + * + * @param contactId the contactId of the contact which just added the user + * @param contactNick the nickname of the contact if available. + * @param account is used to display the account icon and informaiton about the account + * @param hide a bitmask of HideWidget used to hide some widget. By default, everything is shown. + * + */ + ContactAddedNotifyDialog(const QString& contactId, const QString& contactNick=QString::null, + Kopete::Account *account=0L, uint hide=0x00); + + /** + * @brief Destructor + */ + ~ContactAddedNotifyDialog(); + + /** + * @brief return if the user has checked the "authorize" checkbox + * @return true if the authorize checkbox is checked, false otherwise + */ + bool authorized() const; + + /** + * @brief return if the user has checked the "add" checkbox + * @return true if the add checkbox is checked, false otherwise + */ + bool added() const; + + /** + * @brief return the display name the user has entered + */ + QString displayName() const; + + /** + * @brief return the group the user has selected + * + * If the user has entered a group which doesn't exist yet, it will be created now + */ + Group* group() const; + +public slots: + + /** + * @brief create a metacontact. + * + * This function only works if the add checkbox is checked, otherwise, + * it will return 0L. + * + * it uses the Account::addContact function to add the contact + * + * @return the new metacontact created, or 0L if the operation failed. + */ + MetaContact *addContact() const; + +signals: + /** + * @brief the dialog has been applied + * @param contactId is the id of the contact passed in the constructor. + */ + void applyClicked(const QString &contactId); + + /** + * @brief the button "info" has been pressed + * If you haven't hidden the more info button, you should connect this + * signal to a slot which show a dialog with more info about the + * contact. + * + * hint: you can use sender() as parent of the new dialog + * @param contactId is the id of the contact passed in the constructor. + */ + void infoClicked(const QString &contactId); + + +private slots: + void slotAddresseeSelected( const KABC::Addressee &); + void slotInfoClicked(); + void slotFinished(); + +private: + struct Private; + Private *d; +}; + + + +} // namespace UI +} // namespace Kopete +#endif diff --git a/kopete/libkopete/ui/contactaddednotifywidget.ui b/kopete/libkopete/ui/contactaddednotifywidget.ui new file mode 100644 index 00000000..47d3f070 --- /dev/null +++ b/kopete/libkopete/ui/contactaddednotifywidget.ui @@ -0,0 +1,260 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ContactAddedNotifyWidget</class> +<author>Olivier Goffart</author> +<widget class="QWidget"> + <property name="name"> + <cstring>Form2</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>466</width> + <height>342</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_label</cstring> + </property> + <property name="text"> + <string>The contact XXX added you in his contactlist</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>151</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KPushButton"> + <property name="name"> + <cstring>m_infoButton</cstring> + </property> + <property name="text"> + <string>Read More Info About This Contact</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_authorizeCb</cstring> + </property> + <property name="text"> + <string>Authorize this contact to see my status</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_addCb</cstring> + </property> + <property name="text"> + <string>Add this contact in my contactlist</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>m_contactInfoBox</cstring> + </property> + <property name="title"> + <string></string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout19</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel7</cstring> + </property> + <property name="text"> + <string>Display name:</string> + </property> + <property name="toolTip" stdset="0"> + <string>The display name of the contact. Leave it empty to use the contact nickname</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the contact display name. This is how the contact will appears in the contactlist. +Leave it empty if you want to see the contact nickname as display name.</string> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>m_displayNameEdit</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>The display name of the contact. Leave it empty to use the contact nickname</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the contact display name. This is how the contact will appears in the contactlist. +Leave it empty if you want to see the contact nickname as display name.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel5</cstring> + </property> + <property name="text"> + <string>In the group:</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the group where the contact should be added. Leave it empty to add it in the top level group.</string> + </property> + </widget> + <widget class="KComboBox"> + <property name="name"> + <cstring>m_groupList</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="editable"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the group where the contact should be added. Leave it empty to add it in the top level group.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel6</cstring> + </property> + <property name="text"> + <string>Addressbook link:</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer11</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>51</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="Kopete::UI::AddressBookLinkWidget"> + <property name="name"> + <cstring>widAddresseeLink</cstring> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer21</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>21</width> + <height>40</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<connections> + <connection> + <sender>m_addCb</sender> + <signal>toggled(bool)</signal> + <receiver>m_contactInfoBox</receiver> + <slot>setEnabled(bool)</slot> + </connection> +</connections> +<customwidgets> + <customwidget> + <class>Kopete::UI::AddressBookLinkWidget</class> + <header>addressbooklinkwidget.h</header> + </customwidget> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kcombobox.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/editaccountwidget.cpp b/kopete/libkopete/ui/editaccountwidget.cpp new file mode 100644 index 00000000..7428a8ad --- /dev/null +++ b/kopete/libkopete/ui/editaccountwidget.cpp @@ -0,0 +1,49 @@ +/* + editaccountwidget.cpp - Kopete Account Widget + + Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org> + Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "editaccountwidget.h" + +class KopeteEditAccountWidgetPrivate +{ +public: + Kopete::Account *account; +}; + +KopeteEditAccountWidget::KopeteEditAccountWidget( Kopete::Account *account ) +{ + d = new KopeteEditAccountWidgetPrivate; + d->account = account; +} + +KopeteEditAccountWidget::~KopeteEditAccountWidget() +{ + delete d; +} + +Kopete::Account * KopeteEditAccountWidget::account() const +{ + return d->account; +} + +void KopeteEditAccountWidget::setAccount( Kopete::Account *account ) +{ + d->account = account; +} + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/editaccountwidget.h b/kopete/libkopete/ui/editaccountwidget.h new file mode 100644 index 00000000..533c90ff --- /dev/null +++ b/kopete/libkopete/ui/editaccountwidget.h @@ -0,0 +1,104 @@ +/* + editaccountwidget.h - Kopete Account Widget + + Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org> + Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef EDITACCOUNTWIDGET_H +#define EDITACCOUNTWIDGET_H + +#include "kopete_export.h" + +namespace Kopete +{ +class Account; +} + +class KopeteEditAccountWidgetPrivate; + +/** + * @author Olivier Goffart <ogoffart @ kde.org> + * + * This class is used by the protocol plugins to add specific protocol fields in the add account wizard, + * or in the account preferences. If the given account is 0L, then you will have to create a new account + * in @ref apply(). + * + * Each protocol has to subclass this class, and the protocol's edit account page MUST inherits from + * QWidget too. + * + * We suggest to put at least these fields in the page: + * + * - The User login, or the accountId. you can retrieve it from @ref Kopete::Account::accountId(). This + * field has to be marked as ReadOnly or shown as a label if the account already exists. Remember + * that accountId should be constant after account creation! + * + * - The password, and the remember password checkboxes. + * + * - The auto connect checkbox: use @ref Kopete::Account::excludeConnect() and + * @ref Kopete::Account::setExcludeConnect() to get/set this flag. + * + * You may add other custom fields, e.g. the nickname. To save or retrieve these settings use + * @ref Kopete::ContactListElement::pluginData() with your protocol as plugin. + */ +class KOPETE_EXPORT KopeteEditAccountWidget +{ +public: + /** + * Constructor. + * + * If 'account' is 0L we are in the 'add account wizard', otherwise + * we are editing an existing account. + */ + KopeteEditAccountWidget( Kopete::Account *account ); + + /** + * Destructor + */ + virtual ~KopeteEditAccountWidget(); + + /** + * This method must be reimplemented. + * It does the same as @ref AddContactPage::validateData() + */ + virtual bool validateData() = 0; + + /** + * Create a new account if we are in the 'add account wizard', + * otherwise update the existing account. + */ + virtual Kopete::Account *apply() = 0; + +protected: + /** + * Get a pointer to the Kopete::Account passed to the constructor. + * You can modify it any way you like, just don't delete the object. + */ + Kopete::Account * account() const; + + /** + * Set the account + */ + // FIXME: Is it possible to make the API not require this? A const account + // in this widget seems a lot cleaner to me - Martijn + void setAccount( Kopete::Account *account ); + +private: + KopeteEditAccountWidgetPrivate *d; +}; + +// vim: set noet ts=4 sts=4 sw=4: + +#endif + diff --git a/kopete/libkopete/ui/fileconfirmbase.ui b/kopete/libkopete/ui/fileconfirmbase.ui new file mode 100644 index 00000000..3d697b0f --- /dev/null +++ b/kopete/libkopete/ui/fileconfirmbase.ui @@ -0,0 +1,151 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>FileConfirmBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>FileConfirmBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>410</width> + <height>307</height> + </rect> + </property> + <property name="caption"> + <string>A User Would Like to Send You a File</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>3</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>A user is trying to send you a file. The file will only be downloaded if you accept this dialog. If you do not wish to receive it, please click 'Refuse'. This file will never be executed by Kopete at any point during or after the transfer.</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel1_2</cstring> + </property> + <property name="text"> + <string>From:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel7</cstring> + </property> + <property name="text"> + <string>File name:</string> + </property> + </widget> + <widget class="KLineEdit" row="6" column="1"> + <property name="name"> + <cstring>m_saveto</cstring> + </property> + </widget> + <widget class="KPushButton" row="6" column="2"> + <property name="name"> + <cstring>cmdBrowse</cstring> + </property> + <property name="text"> + <string>&Browse...</string> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>TextLabel11</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel8</cstring> + </property> + <property name="text"> + <string>Description:</string> + </property> + </widget> + <widget class="QTextEdit" row="3" column="1" rowspan="2" colspan="2"> + <property name="name"> + <cstring>m_description</cstring> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + <spacer row="4" column="0"> + <property name="name"> + <cstring>Spacer6</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>TextLabel13</cstring> + </property> + <property name="text"> + <string>Save to:</string> + </property> + </widget> + <widget class="KLineEdit" row="1" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_from</cstring> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + <widget class="KLineEdit" row="2" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_filename</cstring> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + <widget class="KLineEdit" row="5" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_size</cstring> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/kopete.widgets b/kopete/libkopete/ui/kopete.widgets new file mode 100644 index 00000000..7c441d0f --- /dev/null +++ b/kopete/libkopete/ui/kopete.widgets @@ -0,0 +1,24 @@ +[Global] +PluginName=KopeteWidgets +Includes=kinstance.h +Init=new KInstance("kopetewidgets"); + +[Kopete::UI::ListView::ListView] +ToolTip=List View (Kopete) +WhatsThis=A component capable list view widget. +IncludeFile=kopetelistview.h +Group=Views (Kopete) + +[Kopete::UI::ListView::SearchLine] +ToolTip=List View Search Line (Kopete) +WhatsThis=Search line able to use Kopete custom list View. +IncludeFile=kopetelistviewsearchline.h +ConstructorArgs=(parent, 0, name) +Group=Input (Kopete) + +[Kopete::UI::AddressBookLinkWidget] +ToolTip=Address Book Link Widget (Kopete) +WhatsThis=KABC::Addressee display/selector +IncludeFile=addressbooklinkwidget.h +ConstructorArgs=(parent, name) +Group=Input (Kopete) diff --git a/kopete/libkopete/ui/kopeteawaydialogbase.ui b/kopete/libkopete/ui/kopeteawaydialogbase.ui new file mode 100644 index 00000000..783fe4da --- /dev/null +++ b/kopete/libkopete/ui/kopeteawaydialogbase.ui @@ -0,0 +1,85 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>KopeteAwayDialog_Base</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KopeteAwayDialog_Base</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>322</width> + <height>192</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>Please specify an away message, or choose a predefined one.</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter|AlignLeft</set> + </property> + <property name="wordwrap" stdset="0"> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>txtOneShot</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>300</width> + <height>0</height> + </size> + </property> + </widget> + <widget class="KComboBox"> + <property name="name"> + <cstring>cmbHistory</cstring> + </property> + <property name="editable"> + <bool>false</bool> + </property> + <property name="insertionPolicy"> + <enum>AtCurrent</enum> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kopete/libkopete/ui/kopetecontactaction.cpp b/kopete/libkopete/ui/kopetecontactaction.cpp new file mode 100644 index 00000000..d02c2ff2 --- /dev/null +++ b/kopete/libkopete/ui/kopetecontactaction.cpp @@ -0,0 +1,54 @@ +/* + kopetecontactaction.cpp - KAction for selecting a Kopete::Contact + + Copyright (c) 2003 by Martijn Klingens <klingens@kde.org> + + Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetecontactaction.h" + +#include "kopetemetacontact.h" +#include "kopetecontact.h" +#include "kopeteonlinestatus.h" + +KopeteContactAction::KopeteContactAction( Kopete::Contact *contact, const QObject *receiver, + const char *slot, KAction *parent ) +: KAction( contact->metaContact()->displayName(), QIconSet( contact->onlineStatus().iconFor( contact ) ), KShortcut(), + parent, contact->contactId().latin1() ) +{ + m_contact = contact; + + connect( this, SIGNAL( activated() ), SLOT( slotContactActionActivated() ) ); + connect( this, SIGNAL( activated( Kopete::Contact * ) ), receiver, slot ); +} + +KopeteContactAction::~KopeteContactAction() +{ +} + +void KopeteContactAction::slotContactActionActivated() +{ + emit activated( m_contact ); +} + +Kopete::Contact * KopeteContactAction::contact() const +{ + return m_contact; +} + + +#include "kopetecontactaction.moc" + +// vim: set noet ts=4 sts=4 sw=4: + + diff --git a/kopete/libkopete/ui/kopetecontactaction.h b/kopete/libkopete/ui/kopetecontactaction.h new file mode 100644 index 00000000..bb9d9f76 --- /dev/null +++ b/kopete/libkopete/ui/kopetecontactaction.h @@ -0,0 +1,61 @@ +/* + kopetecontactaction.cpp - KAction for selecting a Kopete::Contact + + Copyright (c) 2003 by Martijn Klingens <klingens@kde.org> + + Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef __kopetecontactaction_h__ +#define __kopetecontactaction_h__ + +#include <kaction.h> +#include "kopete_export.h" + +namespace Kopete +{ +class Contact; +} + +/** + * @author Martijn Klingens <klingens@kde.org> + */ +class KOPETE_EXPORT KopeteContactAction : public KAction +{ + Q_OBJECT + +public: + /** + * Create a new KopeteContactAction + */ + KopeteContactAction( Kopete::Contact *contact, const QObject* receiver, const char* slot, KAction* parent ); + ~KopeteContactAction(); + + Kopete::Contact * contact() const; + +signals: + /** + * Overloaded signal to get the selected contact + */ + void activated( Kopete::Contact *action ); + +private slots: + void slotContactActionActivated(); + +private: + Kopete::Contact *m_contact; +}; + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/kopetefileconfirmdialog.cpp b/kopete/libkopete/ui/kopetefileconfirmdialog.cpp new file mode 100644 index 00000000..01036a05 --- /dev/null +++ b/kopete/libkopete/ui/kopetefileconfirmdialog.cpp @@ -0,0 +1,117 @@ +/* + kopetefileconfirmdialog.cpp + + Copyright (c) 2003-2004 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qtextedit.h> + +#include <klineedit.h> +#include <kconfig.h> +#include <klocale.h> +#include <kfiledialog.h> +#include <kpushbutton.h> +#include <kmessagebox.h> + +//#include "kopetetransfermanager.h" +#include "fileconfirmbase.h" +#include "kopetefileconfirmdialog.h" + +#include "kopetemetacontact.h" +#include "kopetecontact.h" + +KopeteFileConfirmDialog::KopeteFileConfirmDialog(const Kopete::FileTransferInfo &info,const QString& description,QWidget *parent, const char *name ) +: KDialogBase( parent, name, false, i18n( "A User Would Like to Send You a File" ), + KDialogBase::User1 | KDialogBase::User2, KDialogBase::User1, true, i18n( "&Refuse" ), i18n( "&Accept" ) ), + m_info( info ) +{ + setWFlags( WDestructiveClose ); + m_emited=false; + + m_view=new FileConfirmBase(this, "FileConfirmView"); + m_view->m_from->setText( info.contact()->metaContact()->displayName() + QString::fromLatin1( " <" ) + + info.contact()->contactId() + QString::fromLatin1( "> " ) ); + m_view->m_size->setText( KGlobal::locale()->formatNumber( long( info.size() ), 0 ) ); + m_view->m_description->setText( description ); + m_view->m_filename->setText( info.file() ); + + KGlobal::config()->setGroup("File Transfer"); + const QString defaultPath=KGlobal::config()->readEntry("defaultPath" , QDir::homeDirPath() ); + m_view->m_saveto->setText(defaultPath + QString::fromLatin1( "/" ) + info.file() ); + + setMainWidget(m_view); + + connect(m_view->cmdBrowse, SIGNAL(clicked()), this, SLOT(slotBrowsePressed())); +} + +KopeteFileConfirmDialog::~KopeteFileConfirmDialog() +{ +} + +void KopeteFileConfirmDialog::slotBrowsePressed() +{ + QString saveFileName = KFileDialog::getSaveFileName( m_view->m_saveto->text(), QString::fromLatin1( "*" ), 0L , i18n( "File Transfer" ) ); + if ( !saveFileName.isNull()) + { + m_view->m_saveto->setText(saveFileName); + } +} + +void KopeteFileConfirmDialog::slotUser2() +{ + m_emited=true; + KURL url(m_view->m_saveto->text()); + if(url.isValid() && url.isLocalFile() ) + { + const QString directory=url.directory(); + if(!directory.isEmpty()) + { + KGlobal::config()->setGroup("File Transfer"); + KGlobal::config()->writeEntry("defaultPath" , directory ); + } + + if(QFile(m_view->m_saveto->text()).exists()) + { + int ret=KMessageBox::warningContinueCancel(this, i18n("The file '%1' already exists.\nDo you want to overwrite it ?").arg(m_view->m_saveto->text()) , + i18n("Overwrite File") , KStdGuiItem::save()); + if(ret==KMessageBox::Cancel) + return; + } + + emit accepted(m_info,m_view->m_saveto->text()); + close(); + } + else + KMessageBox::queuedMessageBox (this, KMessageBox::Sorry, i18n("You must provide a valid local filename") ); +} + +void KopeteFileConfirmDialog::slotUser1() +{ + m_emited=true; + emit refused(m_info); + close(); +} + +void KopeteFileConfirmDialog::closeEvent( QCloseEvent *e) +{ + if(!m_emited) + { + m_emited=true; + emit refused(m_info); + } + KDialogBase::closeEvent(e); +} + +#include "kopetefileconfirmdialog.moc" + diff --git a/kopete/libkopete/ui/kopetefileconfirmdialog.h b/kopete/libkopete/ui/kopetefileconfirmdialog.h new file mode 100644 index 00000000..20d58d51 --- /dev/null +++ b/kopete/libkopete/ui/kopetefileconfirmdialog.h @@ -0,0 +1,57 @@ +/* + kopetefileconfirmdialog.h + + Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETEFILECONFIRMDIALOG_H +#define KOPETEFILECONFIRMDIALOG_H + +#include <qwidget.h> +#include <kdialogbase.h> +#include "kopetetransfermanager.h" + +class FileConfirmBase; + +/** + *@author Olivier Goffart + */ + +class KopeteFileConfirmDialog : public KDialogBase +{ +Q_OBJECT + +public: + KopeteFileConfirmDialog(const Kopete::FileTransferInfo &info,const QString& description=QString::null, QWidget *parent=0, const char* name=0); + ~KopeteFileConfirmDialog(); + +private: + FileConfirmBase* m_view; + Kopete::FileTransferInfo m_info; + bool m_emited; + +public slots: + void slotBrowsePressed(); + +protected slots: + virtual void slotUser2(); + virtual void slotUser1(); + virtual void closeEvent( QCloseEvent *e); + +signals: + void accepted(const Kopete::FileTransferInfo &info, const QString &filename); + void refused(const Kopete::FileTransferInfo &info); +}; + +#endif diff --git a/kopete/libkopete/ui/kopetelistview.cpp b/kopete/libkopete/ui/kopetelistview.cpp new file mode 100644 index 00000000..594f0920 --- /dev/null +++ b/kopete/libkopete/ui/kopetelistview.cpp @@ -0,0 +1,215 @@ +/* + kopetelistview.cpp - List View providing support for ListView::Items + + Copyright (c) 2004 by Engin AYDOGAN <engin@bzzzt.biz> + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetelistview.h" +#include "kopetelistviewitem.h" +#include "kopeteuiglobal.h" +#include "kopeteglobal.h" +#include "kopeteprefs.h" + +#include <qapplication.h> +#include <kglobal.h> +#include <kconfig.h> +#include <kdebug.h> + +#include <qtimer.h> +#include <qtooltip.h> +#include <qstyle.h> + +#include <utility> +#include <memory> + +namespace Kopete { +namespace UI { +namespace ListView { + +/* + Custom QToolTip for the list view. + The decision whether or not to show tooltips is taken in + maybeTip(). See also the QListView sources from Qt itself. + Delegates to the list view items. +*/ +class ToolTip : public QToolTip +{ +public: + ToolTip( QWidget *parent, ListView *lv ); + virtual ~ToolTip(); + + void maybeTip( const QPoint &pos ); + +private: + ListView *m_listView; +}; + +ToolTip::ToolTip( QWidget *parent, ListView *lv ) + : QToolTip( parent ) +{ + m_listView = lv; +} + +ToolTip::~ToolTip() +{ +} + +void ToolTip::maybeTip( const QPoint &pos ) +{ + if( !parentWidget() || !m_listView ) + return; + + if( Item *item = dynamic_cast<Item*>( m_listView->itemAt( pos ) ) ) + { + QRect itemRect = m_listView->itemRect( item ); + + uint leftMargin = m_listView->treeStepSize() * + ( item->depth() + ( m_listView->rootIsDecorated() ? 1 : 0 ) ) + + m_listView->itemMargin(); + + uint xAdjust = itemRect.left() + leftMargin; + uint yAdjust = itemRect.top(); + QPoint relativePos( pos.x() - xAdjust, pos.y() - yAdjust ); + + std::pair<QString,QRect> toolTip = item->toolTip( relativePos ); + if ( toolTip.first.isEmpty() ) + return; + + toolTip.second.moveBy( xAdjust, yAdjust ); +// kdDebug( 14000 ) << k_funcinfo << "Adding tooltip: itemRect: " +// << toolTip.second << ", tooltip: " << toolTip.first << endl; + tip( toolTip.second, toolTip.first ); + } +} + +struct ListView::Private +{ + QTimer sortTimer; + std::auto_ptr<ToolTip> toolTip; + //! C-tor + Private() {} +}; + +ListView::ListView( QWidget *parent, const char *name ) + : KListView( parent, name ), d( new Private ) +{ + connect( &d->sortTimer, SIGNAL( timeout() ), this, SLOT( slotSort() ) ); + + // We have our own tooltips, don't use the default QListView ones + setShowToolTips( false ); + d->toolTip.reset( new ToolTip( viewport(), this ) ); + + connect( this, SIGNAL( contextMenu( KListView *, QListViewItem *, const QPoint & ) ), + SLOT( slotContextMenu( KListView *, QListViewItem *, const QPoint & ) ) ); + connect( this, SIGNAL( doubleClicked( QListViewItem * ) ), + SLOT( slotDoubleClicked( QListViewItem * ) ) ); + + // set up flags for nicer painting + clearWFlags( WStaticContents ); + setWFlags( WNoAutoErase ); + + // clear the appropriate flags from the viewport - qt docs say we have to mask + // these flags out of the QListView to make weirdly painted list items work, but + // that doesn't do the job. masking them out of the viewport does. +// class MyWidget : public QWidget { public: using QWidget::clearWFlags; }; +// static_cast<MyWidget*>( viewport() )->clearWFlags( WStaticContents ); +// static_cast<MyWidget*>( viewport() )->setWFlags( WNoAutoErase ); + + // The above causes compiler errors with the (broken) native TRU64 and IRIX compilers. + // This should make it compile for both platforms and still seems to work. + // This is, of course, a nasty hack, but it works, so... + static_cast<ListView*>(viewport())->clearWFlags( WStaticContents ); + static_cast<ListView*>(viewport())->setWFlags( WNoAutoErase ); +} + +ListView::~ListView() +{ + delete d; +} + +void ListView::slotDoubleClicked( QListViewItem *item ) +{ + kdDebug( 14000 ) << k_funcinfo << endl; + + if ( item ) + setOpen( item, !isOpen( item ) ); +} + +void ListView::slotContextMenu( KListView * /*listview*/, + QListViewItem *item, const QPoint &/*point*/ ) +{ + if ( item && !item->isSelected() ) + { + clearSelection(); + item->setSelected( true ); + } + if ( !item ) + clearSelection(); + +// if( Item *myItem = dynamic_cast<Item*>( item ) ) + ;// TODO: myItem->contextMenu( point ); +} + +void ListView::setShowTreeLines( bool bShowAsTree ) +{ + if ( bShowAsTree ) + { + setRootIsDecorated( true ); + setTreeStepSize( 20 ); + } + else + { + setRootIsDecorated( false ); + setTreeStepSize( 0 ); + } + // TODO: relayout all items. their width may have changed, but they won't know about it. +} + +/* This is a small hack ensuring that only F2 triggers inline + * renaming. Won't win a beauty award, but whoever wrote it thinks + * relying on the fact that QListView intercepts and processes the + * F2 event through this event filter is sorta safe. + * + * Also use enter to execute the item since executed is not usually + * called when enter is pressed. + */ +void ListView::keyPressEvent( QKeyEvent *e ) +{ + QListViewItem *item = currentItem(); + if ( (e->key() == Qt::Key_F2) && item && item->isVisible() ) + rename( item, 0 ); + else if ( (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) && item && item->isVisible() ) + { + // must provide a point within the item; emitExecute checks for this + QPoint p = viewport()->mapToGlobal(itemRect(item).center()); + emitExecute( currentItem(), p, 0 ); + } + else + KListView::keyPressEvent(e); +} + +void ListView::delayedSort() +{ + if ( !d->sortTimer.isActive() ) + d->sortTimer.start( 500, true ); +} + +} // END namespace ListView +} // END namespace UI +} // END namespace Kopete + +#include "kopetelistview.moc" + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopetelistview.h b/kopete/libkopete/ui/kopetelistview.h new file mode 100644 index 00000000..8b2c579b --- /dev/null +++ b/kopete/libkopete/ui/kopetelistview.h @@ -0,0 +1,74 @@ +/* + kopetelistview.h - List View providing extra support for ListView::Items + + Copyright (c) 2005 by Engin AYDOGAN <engin@bzzzt.biz> + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETE_LISTVIEW_H +#define KOPETE_LISTVIEW_H + +#include <klistview.h> + +namespace Kopete { +namespace UI { +namespace ListView { + +/** + * @author Engin AYDOGAN <engin@bzzzt.biz> + * @author Richard Smith <kde@metafoo.co.uk> + */ +class ListView : public KListView +{ + Q_OBJECT + +public: + ListView( QWidget *parent = 0, const char *name = 0 ); + ~ListView(); + + /** + * Schedule a delayed sort operation. Sorts will be withheld for at most + * half a second, after which they will be performed. This way multiple + * sort calls can be safely bundled without writing complex code to avoid + * the sorts entirely. + */ + void delayedSort(); + + /** + * Set whether to show the lines and +/- boxes in the tree + */ + void setShowTreeLines( bool bShowAsTree ); + +public slots: + /** + * Calls QListView::sort() + */ + void slotSort() { sort(); } +protected: + virtual void keyPressEvent( QKeyEvent *e ); +private slots: + void slotContextMenu(KListView*,QListViewItem *item, const QPoint &point ); + void slotDoubleClicked( QListViewItem *item ); +private: + struct Private; + Private *d; +}; + +} // END namespace ListView +} // END namespace UI +} // END namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopetelistviewitem.cpp b/kopete/libkopete/ui/kopetelistviewitem.cpp new file mode 100644 index 00000000..fda2ff4c --- /dev/null +++ b/kopete/libkopete/ui/kopetelistviewitem.cpp @@ -0,0 +1,1314 @@ +/* + kopetelistviewitem.cpp - Kopete's modular QListViewItems + + Copyright (c) 2005 by Engin AYDOGAN <engin@bzzzt.biz> + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "kopetecontact.h" +#include "kopetelistviewitem.h" +#include "kopeteemoticons.h" +#include "kopeteonlinestatus.h" + +#include <kdebug.h> +#include <kiconloader.h> +#include <kstringhandler.h> + +#include <qapplication.h> +#include <qpixmap.h> +#include <qpainter.h> +#include <qptrlist.h> +#include <qrect.h> +#include <qtimer.h> +#include <qheader.h> +#include <qstyle.h> + +#ifdef HAVE_XRENDER +# include <X11/Xlib.h> +# include <X11/extensions/Xrender.h> +#endif + +#include <limits.h> + +namespace Kopete { +namespace UI { +namespace ListView { + +// ComponentBase -------- + +class ComponentBase::Private +{ +public: + QPtrList<Component> components; +}; + +ComponentBase::ComponentBase() + : d( new Private ) +{ +} + +ComponentBase::~ComponentBase() +{ + d->components.setAutoDelete( true ); + delete d; +} + +uint ComponentBase::components() { return d->components.count(); } +Component *ComponentBase::component( uint n ) { return d->components.at( n ); } + +Component *ComponentBase::componentAt( const QPoint &pt ) +{ + for ( uint n = 0; n < components(); ++n ) + { + if ( component( n )->rect().contains( pt ) ) + { + if ( Component *comp = component( n )->componentAt( pt ) ) + return comp; + return component( n ); + } + } + return 0; +} + +void ComponentBase::componentAdded( Component *component ) +{ + d->components.append( component ); +} + +void ComponentBase::componentRemoved( Component *component ) +{ + //TODO: make sure the component is in d->components once and only once. + // if not, the situation is best referred to as 'very very broken indeed'. + d->components.remove( component ); +} + +void ComponentBase::clear() +{ + /* I'm switching setAutoDelete back and forth instead of turning it + * on permenantly, because original author of this class set it to + * auto delete in the dtor, that might have a reason that I can't + * imagine right now */ + bool tmp = d->components.autoDelete(); + d->components.setAutoDelete( true ); + d->components.clear(); + d->components.setAutoDelete( tmp ); +} + +void ComponentBase::componentResized( Component * ) +{ +} + +std::pair<QString,QRect> ComponentBase::toolTip( const QPoint &relativePos ) +{ + for ( uint n = 0; n < components(); ++n ) + if ( component( n )->rect().contains( relativePos ) ) + return component( n )->toolTip( relativePos ); + + return std::make_pair( QString::null, QRect() ); +} + +void ComponentBase::updateAnimationPosition( int p, int s ) +{ + for ( uint n = 0; n < components(); ++n ) + { + Component *comp = component( n ); + QRect start = comp->startRect(); + QRect target = comp->targetRect(); + QRect rc( start.left() + ((target.left() - start.left()) * p) / s, + start.top() + ((target.top() - start.top()) * p) / s, + start.width() + ((target.width() - start.width()) * p) / s, + start.height() + ((target.height() - start.height()) * p) / s ); + comp->setRect( rc ); + comp->updateAnimationPosition( p, s ); + } +} + +// Component -------- + +class Component::Private +{ +public: + Private( ComponentBase *parent ) + : parent( parent ), minWidth( 0 ), minHeight( 0 ) + , growHoriz( false ), growVert( false ) + , tipSource( 0 ) + { + } + ComponentBase *parent; + QRect rect; + QRect startRect, targetRect; + int minWidth, minHeight; + bool growHoriz, growVert; + bool show; /** @since 23-03-2005 */ + ToolTipSource *tipSource; +}; + +Component::Component( ComponentBase *parent ) + : d( new Private( parent ) ) +{ + d->parent->componentAdded( this ); + d->show = true; +} + +int Component::RTTI = Rtti_Component; + +Component::~Component() +{ + d->parent->componentRemoved( this ); + delete d; +} + + +void Component::hide() +{ + d->show = false; +} + +void Component::show() +{ + d->show = true; +} + +bool Component::isShown() +{ + return d->show; +} + +bool Component::isHidden() +{ + return !d->show; +} + +void Component::setToolTipSource( ToolTipSource *source ) +{ + d->tipSource = source; +} + +std::pair<QString,QRect> Component::toolTip( const QPoint &relativePos ) +{ + if ( !d->tipSource ) + return ComponentBase::toolTip( relativePos ); + + QRect rc = rect(); + QString result = (*d->tipSource)( this, relativePos, rc ); + return std::make_pair(result, rc); +} + +QRect Component::rect() { return d->rect; } +QRect Component::startRect() { return d->startRect; } +QRect Component::targetRect() { return d->targetRect; } + +int Component::minWidth() { return d->minWidth; } +int Component::minHeight() { return d->minHeight; } +int Component::widthForHeight( int ) { return minWidth(); } +int Component::heightForWidth( int ) { return minHeight(); } + +bool Component::setMinWidth( int width ) +{ + if ( d->minWidth == width ) return false; + d->minWidth = width; + + d->parent->componentResized( this ); + return true; +} +bool Component::setMinHeight( int height ) +{ + if ( d->minHeight == height ) return false; + d->minHeight = height; + + d->parent->componentResized( this ); + return true; +} + +void Component::layout( const QRect &newRect ) +{ + if ( rect().isNull() ) + d->startRect = QRect( newRect.topLeft(), newRect.topLeft() ); + else + d->startRect = rect(); + d->targetRect = newRect; + //kdDebug(14000) << k_funcinfo << "At " << rect << endl; +} + +void Component::setRect( const QRect &rect ) +{ + d->rect = rect; +} + +void Component::paint( QPainter *painter, const QColorGroup &cg ) +{ + /*painter->setPen( Qt::red ); + painter->drawRect( rect() );*/ + for ( uint n = 0; n < components(); ++n ) + { + if( component( n )->isShown() ) + component( n )->paint( painter, cg ); + } +} + +void Component::repaint() +{ + d->parent->repaint(); +} + +void Component::relayout() +{ + d->parent->relayout(); +} + +void Component::componentAdded( Component *component ) +{ + ComponentBase::componentAdded( component ); + //update( Relayout ); +} + +void Component::componentRemoved( Component *component ) +{ + ComponentBase::componentRemoved( component ); + //update( Relayout ); +} + +// BoxComponent -------- + +class BoxComponent::Private +{ +public: + Private( BoxComponent::Direction dir ) : direction( dir ) {} + BoxComponent::Direction direction; + + static const int padding = 2; +}; + +BoxComponent::BoxComponent( ComponentBase *parent, Direction dir ) + : Component( parent ), d( new Private( dir ) ) +{ +} + +int BoxComponent::RTTI = Rtti_BoxComponent; + +BoxComponent::~BoxComponent() +{ + delete d; +} + +int BoxComponent::widthForHeight( int height ) +{ + if ( d->direction != Horizontal ) + { + int width = 0; + for ( uint n = 0; n < components(); ++n ) + width = QMAX( width, component( n )->widthForHeight( height ) ); + return width; + } + else + { + int width = (components() - 1) * Private::padding; + for ( uint n = 0; n < components(); ++n ) + width += component( n )->widthForHeight( height ); + return width; + } +} + +int BoxComponent::heightForWidth( int width ) +{ + if ( d->direction == Horizontal ) + { + int height = 0; + for ( uint n = 0; n < components(); ++n ) + height = QMAX( height, component( n )->heightForWidth( width ) ); + return height; + } + else + { + int height = (components() - 1) * Private::padding; + for ( uint n = 0; n < components(); ++n ) + height += component( n )->heightForWidth( width ); + return height; + } +} + +void BoxComponent::calcMinSize() +{ + int sum = (components() - 1) * Private::padding, max = 0; + for ( uint n = 0; n < components(); ++n ) + { + Component *comp = component( n ); + if ( d->direction == Horizontal ) + { + max = QMAX( max, comp->minHeight() ); + sum += comp->minWidth(); + } + else + { + max = QMAX( max, comp->minWidth() ); + sum += comp->minHeight(); + } + } + + bool sizeChanged = false; + if ( d->direction == Horizontal ) + { + if ( setMinWidth( sum ) ) sizeChanged = true; + if ( setMinHeight( max ) ) sizeChanged = true; + } + else + { + if ( setMinWidth( max ) ) sizeChanged = true; + if ( setMinHeight( sum ) ) sizeChanged = true; + } + + if ( sizeChanged ) + repaint(); + else + relayout(); +} + +void BoxComponent::layout( const QRect &rect ) +{ + Component::layout( rect ); + + bool horiz = (d->direction == Horizontal); + int fixedSize = 0; + for ( uint n = 0; n < components(); ++n ) + { + Component *comp = component( n ); + if ( horiz ) + fixedSize += comp->minWidth(); + else + fixedSize += comp->minHeight(); + } + + // remaining space after all fixed items have been allocated + int padding = Private::padding; + + // ensure total is at least minXXX. the only time the rect + // will be smaller than that is when we don't fit, and in + // that cases we should pretend that we're wide/high enough. + int total; + if ( horiz ) + total = QMAX( rect.width(), minWidth() ); + else + total = QMAX( rect.height(), minHeight() ); + + int remaining = total - fixedSize - padding * (components() - 1); + + // finally, lay everything out + int pos = 0; + for ( uint n = 0; n < components(); ++n ) + { + Component *comp = component( n ); + + QRect rc; + if ( horiz ) + { + rc.setLeft( rect.left() + pos ); + rc.setTop( rect.top() ); + rc.setHeight( rect.height() ); + int minWidth = comp->minWidth(); + int desiredWidth = comp->widthForHeight( rect.height() ); + rc.setWidth( QMIN( remaining + minWidth, desiredWidth ) ); + pos += rc.width(); + remaining -= rc.width() - minWidth; + } + else + { + rc.setLeft( rect.left() ); + rc.setTop( rect.top() + pos ); + rc.setWidth( rect.width() ); + int minHeight = comp->minHeight(); + int desiredHeight = comp->heightForWidth( rect.width() ); + rc.setHeight( QMIN( remaining + minHeight, desiredHeight ) ); + pos += rc.height(); + remaining -= rc.height() - minHeight; + } + comp->layout( rc & rect ); + pos += padding; + } +} + +void BoxComponent::componentAdded( Component *component ) +{ + Component::componentAdded( component ); + calcMinSize(); +} + +void BoxComponent::componentRemoved( Component *component ) +{ + Component::componentRemoved( component ); + calcMinSize(); +} + +void BoxComponent::componentResized( Component *component ) +{ + Component::componentResized( component ); + calcMinSize(); +} + +// ImageComponent -------- + +class ImageComponent::Private +{ +public: + QPixmap image; +}; + +ImageComponent::ImageComponent( ComponentBase *parent ) + : Component( parent ), d( new Private ) +{ +} + +int ImageComponent::RTTI = Rtti_ImageComponent; + +ImageComponent::ImageComponent( ComponentBase *parent, int minW, int minH ) + : Component( parent ), d( new Private ) +{ + setMinWidth( minW ); + setMinHeight( minH ); + repaint(); +} + +ImageComponent::~ImageComponent() +{ + delete d; +} + +QPixmap ImageComponent::pixmap() +{ + return d->image; +} + +void ImageComponent::setPixmap( const QPixmap &img, bool adjustSize) +{ + d->image = img; + if ( adjustSize ) + { + setMinWidth( img.width() ); + setMinHeight( img.height() ); + } + repaint(); +} + +static QPoint operator+( const QPoint &pt, const QSize &sz ) +{ + return QPoint( pt.x() + sz.width(), pt.y() + sz.height() ); +} + +/*static QPoint operator+( const QSize &sz, const QPoint &pt ) +{ + return pt + sz; +}*/ + +void ImageComponent::paint( QPainter *painter, const QColorGroup & ) +{ + QRect ourRc = rect(); + QRect rc = d->image.rect(); + // center rc within our rect + rc.moveTopLeft( ourRc.topLeft() + (ourRc.size() - rc.size()) / 2 ); + // paint, shrunk to be within our rect + painter->drawPixmap( rc & ourRc, d->image ); +} + +void ImageComponent::scale( int w, int h, QImage::ScaleMode mode ) +{ + QImage im = d->image.convertToImage(); + setPixmap( QPixmap( im.smoothScale( w, h, mode ) ) ); +} +// TextComponent + +class TextComponent::Private +{ +public: + Private() : customColor( false ) {} + QString text; + bool customColor; + QColor color; + QFont font; +}; + +TextComponent::TextComponent( ComponentBase *parent, const QFont &font, const QString &text ) + : Component( parent ), d( new Private ) +{ + setFont( font ); + setText( text ); +} + +int TextComponent::RTTI = Rtti_TextComponent; + +TextComponent::~TextComponent() +{ + delete d; +} + +QString TextComponent::text() +{ + return d->text; +} + +void TextComponent::setText( const QString &text ) +{ + if ( text == d->text ) return; + d->text = text; + relayout(); + calcMinSize(); +} + +QFont TextComponent::font() +{ + return d->font; +} + +void TextComponent::setFont( const QFont &font ) +{ + if ( font == d->font ) return; + d->font = font; + calcMinSize(); +} + +void TextComponent::calcMinSize() +{ + setMinWidth( 0 ); + + if ( !d->text.isEmpty() ) + setMinHeight( QFontMetrics( font() ).height() ); + else + setMinHeight( 0 ); + + repaint(); +} + +int TextComponent::widthForHeight( int ) +{ + // add 2 to place an extra gap between the text and things to its right. + // allegedly if this is not done the protocol icons overlap the text. + // i however have never seen this problem (which would almost certainly + // be a bug somewhere else). + return QFontMetrics( font() ).width( d->text ) + 2; +} + +QColor TextComponent::color() +{ + return d->customColor ? d->color : QColor(); +} + +void TextComponent::setColor( const QColor &color ) +{ + d->color = color; + d->customColor = true; + repaint(); +} + +void TextComponent::setDefaultColor() +{ + d->customColor = false; + repaint(); +} + +void TextComponent::paint( QPainter *painter, const QColorGroup &cg ) +{ + if ( d->customColor ) + painter->setPen( d->color ); + else + painter->setPen( cg.text() ); + QString dispStr = KStringHandler::rPixelSqueeze( d->text, QFontMetrics( font() ), rect().width() ); + painter->setFont( font() ); + painter->drawText( rect(), Qt::SingleLine, dispStr ); +} + +// DisplayNameComponent + +class DisplayNameComponent::Private +{ +public: + QString text; + QFont font; +}; + +DisplayNameComponent::DisplayNameComponent( ComponentBase *parent ) + : BoxComponent( parent ), d( new Private ) +{ +} + +int DisplayNameComponent::RTTI = Rtti_DisplayNameComponent; + +DisplayNameComponent::~DisplayNameComponent() +{ + delete d; +} + +void DisplayNameComponent::layout( const QRect &rect ) +{ + Component::layout( rect ); + + // finally, lay everything out + QRect rc; + int totalWidth = rect.width(); + int usedWidth = 0; + bool exceeded = false; + for ( uint n = 0; n < components(); ++n ) + { + Component *comp = component( n ); + if ( !exceeded ) + { + if ( ( usedWidth + comp->widthForHeight( rect.height() ) ) > totalWidth ) + { + exceeded = true; + // TextComponents can squeeze themselves + if ( comp->rtti() == Rtti_TextComponent ) + { + comp->show(); + comp->layout( QRect( usedWidth+ rect.left(), rect.top(), + totalWidth - usedWidth, + comp->heightForWidth( totalWidth - usedWidth ) ) ); + } else { + comp->hide(); + } + } + else + { + comp->show(); + comp->layout( QRect( usedWidth+ rect.left(), rect.top(), + comp->widthForHeight( rect.height() ), + comp->heightForWidth( rect.width() ) ) ); + } + usedWidth+= comp->widthForHeight( rect.height() ); + } + else + { + // Shall we implement a hide()/show() in Component class ? + comp->hide(); + } + } +} + +void DisplayNameComponent::setText( const QString& text ) +{ + if ( d->text == text ) + return; + d->text = text; + + redraw(); +} + +void DisplayNameComponent::redraw() +{ + QColor color; + for ( uint n = 0; n < components(); ++n ) + if( component( n )->rtti() == Rtti_TextComponent ) + { + ((TextComponent*)component(n))->color(); + } + + QValueList<Kopete::Emoticons::Token> tokens; + QValueList<Kopete::Emoticons::Token>::const_iterator token; + + clear(); // clear childs + + tokens = Kopete::Emoticons::tokenizeEmoticons( d->text ); + ImageComponent *ic; + TextComponent *t; + + QFontMetrics fontMetrics( d->font ); + int fontHeight = fontMetrics.height(); + for ( token = tokens.begin(); token != tokens.end(); ++token ) + { + switch ( (*token).type ) + { + case Kopete::Emoticons::Text: + t = new TextComponent( this, d->font, (*token).text ); + break; + case Kopete::Emoticons::Image: + ic = new ImageComponent( this ); + ic->setPixmap( QPixmap( (*token).picPath ) ); + ic->scale( INT_MAX, fontHeight, QImage::ScaleMin ); + break; + default: + kdDebug( 14010 ) << k_funcinfo << "This should have not happened!" << endl; + } + } + + if(color.isValid()) + setColor( color ); +} + +void DisplayNameComponent::setFont( const QFont& font ) +{ + for ( uint n = 0; n < components(); ++n ) + if( component( n )->rtti() == Rtti_TextComponent ) + ((TextComponent*)component(n))->setFont( font ); + d->font = font; +} + +void DisplayNameComponent::setColor( const QColor& color ) +{ + for ( uint n = 0; n < components(); ++n ) + if( component( n )->rtti() == Rtti_TextComponent ) + ((TextComponent*)component(n))->setColor( color ); +} + +void DisplayNameComponent::setDefaultColor() +{ + for ( uint n = 0; n < components(); ++n ) + if( component( n )->rtti() == Rtti_TextComponent ) + ((TextComponent*)component(n))->setDefaultColor(); +} + +QString DisplayNameComponent::text() +{ + return d->text; +} + +// HSpacerComponent -------- + +HSpacerComponent::HSpacerComponent( ComponentBase *parent ) + : Component( parent ) +{ + setMinWidth( 0 ); + setMinHeight( 0 ); +} + +int HSpacerComponent::RTTI = Rtti_HSpacerComponent; + +int HSpacerComponent::widthForHeight( int ) +{ + return INT_MAX; +} + +// VSpacerComponent -------- + +VSpacerComponent::VSpacerComponent( ComponentBase *parent ) + : Component( parent ) +{ + setMinWidth( 0 ); + setMinHeight( 0 ); +} + +int VSpacerComponent::RTTI = Rtti_VSpacerComponent; + +int VSpacerComponent::heightForWidth( int ) +{ + return INT_MAX; +} + +////////////////// ContactComponent ///////////////////////// + +class ContactComponent::Private +{ +public: + Kopete::Contact *contact; + int iconSize; +}; + +ContactComponent::ContactComponent( ComponentBase *parent, Kopete::Contact *contact, int iconSize) : ImageComponent( parent ) , d( new Private ) +{ + d->contact = contact; + d->iconSize = iconSize; + updatePixmap(); +} + +ContactComponent::~ContactComponent() +{ + delete d; +} + +void ContactComponent::updatePixmap() +{ + setPixmap( contact()->onlineStatus().iconFor( contact(), d->iconSize ) ); +} +Kopete::Contact *ContactComponent::contact() +{ + return d->contact; +} + +// we don't need to use a tooltip source here - this way is simpler +std::pair<QString,QRect> ContactComponent::toolTip( const QPoint &/*relativePos*/ ) +{ + return std::make_pair(d->contact->toolTip(),rect()); +} + +////////////////// SpacerComponent ///////////////////////// + +SpacerComponent::SpacerComponent( ComponentBase *parent, int w, int h ) : Component( parent ) +{ + setMinWidth(w); + setMinHeight(h); +} + +// Item -------- + +/** + * A periodic timer intended to be shared amongst multiple objects. Will run only + * if an object is attached to it. + */ +class SharedTimer : private QTimer +{ + int period; + int users; +public: + SharedTimer( int period ) : period(period), users(0) {} + void attach( QObject *target, const char *slot ) + { + connect( this, SIGNAL(timeout()), target, slot ); + if( users++ == 0 ) + start( period ); + //kdDebug(14000) << "SharedTimer::attach: users is now " << users << "\n"; + } + void detach( QObject *target, const char *slot ) + { + disconnect( this, SIGNAL(timeout()), target, slot ); + if( --users == 0 ) + stop(); + //kdDebug(14000) << "SharedTimer::detach: users is now " << users << "\n"; + } +}; + +class SharedTimerRef +{ + SharedTimer &timer; + QObject * const object; + const char * const slot; + bool attached; +public: + SharedTimerRef( SharedTimer &timer, QObject *obj, const char *slot ) + : timer(timer), object(obj), slot(slot), attached(false) + { + } + void start() + { + if( attached ) return; + timer.attach( object, slot ); + attached = true; + } + void stop() + { + if( !attached ) return; + timer.detach( object, slot ); + attached = false; + } + bool isActive() + { + return attached; + } +}; + +class Item::Private +{ +public: + Private( Item *item ) + : layoutAnimateTimer( theLayoutAnimateTimer(), item, SLOT( slotLayoutAnimateItems() ) ) + , animateLayout( true ), opacity( 1.0 ) + , visibilityTimer( theVisibilityTimer(), item, SLOT( slotUpdateVisibility() ) ) + , visibilityLevel( 0 ), visibilityTarget( false ), searchMatch( true ) + { + } + + QTimer layoutTimer; + + //QTimer layoutAnimateTimer; + SharedTimerRef layoutAnimateTimer; + SharedTimer &theLayoutAnimateTimer() + { + static SharedTimer timer( 10 ); + return timer; + } + + bool animateLayout; + int layoutAnimateSteps; + static const int layoutAnimateStepsTotal = 10; + + float opacity; + + //QTimer visibilityTimer; + SharedTimerRef visibilityTimer; + SharedTimer &theVisibilityTimer() + { + static SharedTimer timer( 40 ); + return timer; + } + + int visibilityLevel; + bool visibilityTarget; + static const int visibilityFoldSteps = 7; +#ifdef HAVE_XRENDER + static const int visibilityFadeSteps = 7; +#else + static const int visibilityFadeSteps = 0; +#endif + static const int visibilityStepsTotal = visibilityFoldSteps + visibilityFadeSteps; + + bool searchMatch; + + static bool animateChanges; + static bool fadeVisibility; + static bool foldVisibility; +}; + +bool Item::Private::animateChanges = true; +bool Item::Private::fadeVisibility = true; +bool Item::Private::foldVisibility = true; + +Item::Item( QListViewItem *parent, QObject *owner, const char *name ) + : QObject( owner, name ), KListViewItem( parent ), d( new Private(this) ) +{ + initLVI(); +} + +Item::Item( QListView *parent, QObject *owner, const char *name ) + : QObject( owner, name ), KListViewItem( parent ), d( new Private(this) ) +{ + initLVI(); +} + +Item::~Item() +{ + delete d; +} + +void Item::setEffects( bool animation, bool fading, bool folding ) +{ + Private::animateChanges = animation; + Private::fadeVisibility = fading; + Private::foldVisibility = folding; +} + +void Item::initLVI() +{ + connect( listView()->header(), SIGNAL( sizeChange( int, int, int ) ), SLOT( slotColumnResized() ) ); + connect( &d->layoutTimer, SIGNAL( timeout() ), SLOT( slotLayoutItems() ) ); + //connect( &d->layoutAnimateTimer, SIGNAL( timeout() ), SLOT( slotLayoutAnimateItems() ) ); + //connect( &d->visibilityTimer, SIGNAL( timeout() ), SLOT( slotUpdateVisibility() ) ); + setVisible( false ); + setTargetVisibility( true ); +} + +void Item::slotColumnResized() +{ + scheduleLayout(); + // if we've been resized, don't animate the layout + d->animateLayout = false; +} + +void Item::scheduleLayout() +{ + // perform a delayed layout in order to speed it all up + if ( ! d->layoutTimer.isActive() ) + d->layoutTimer.start( 30, true ); +} + +void Item::slotLayoutItems() +{ + d->layoutTimer.stop(); + + for ( uint n = 0; n < components(); ++n ) + { + int width = listView()->columnWidth(n); + if ( n == 0 ) + { + int d = depth() + (listView()->rootIsDecorated() ? 1 : 0); + width -= d * listView()->treeStepSize(); + } + + int height = component( n )->heightForWidth( width ); + component( n )->layout( QRect( 0, 0, width, height ) ); + //kdDebug(14000) << k_funcinfo << "Component " << n << " is " << width << " x " << height << endl; + } + + if ( Private::animateChanges && d->animateLayout && !d->visibilityTimer.isActive() ) + { + d->layoutAnimateTimer.start(); + //if ( !d->layoutAnimateTimer.isActive() ) + // d->layoutAnimateTimer.start( 10 ); + d->layoutAnimateSteps = 0; + } + else + { + d->layoutAnimateSteps = Private::layoutAnimateStepsTotal; + d->animateLayout = true; + } + slotLayoutAnimateItems(); +} + +void Item::slotLayoutAnimateItems() +{ + if ( ++d->layoutAnimateSteps >= Private::layoutAnimateStepsTotal ) + d->layoutAnimateTimer.stop(); + + const int s = Private::layoutAnimateStepsTotal; + const int p = QMIN( d->layoutAnimateSteps, s ); + + updateAnimationPosition( p, s ); + setHeight(0); + repaint(); +} + +float Item::opacity() +{ + return d->opacity; +} + +void Item::setOpacity( float opacity ) +{ + if ( d->opacity == opacity ) return; + d->opacity = opacity; + repaint(); +} + +void Item::setSearchMatch( bool match ) +{ + d->searchMatch = match; + + if ( !match ) + setVisible( false ); + else + { + kdDebug(14000) << k_funcinfo << " match: " << match << ", vis timer active: " << d->visibilityTimer.isActive() + << ", target visibility: " << targetVisibility() << endl; + if ( d->visibilityTimer.isActive() ) + setVisible( true ); + else + setVisible( targetVisibility() ); + } +} + +bool Item::targetVisibility() +{ + return d->visibilityTarget; +} + +void Item::setTargetVisibility( bool vis ) +{ + if ( d->visibilityTarget == vis ) + { + // in case we're getting called because our parent was shown and + // we need to be rehidden + if ( !d->visibilityTimer.isActive() ) + setVisible( vis && d->searchMatch ); + return; + } + d->visibilityTarget = vis; + d->visibilityTimer.start(); + //d->visibilityTimer.start( 40 ); + if ( targetVisibility() ) + setVisible( d->searchMatch ); + slotUpdateVisibility(); +} + +void Item::slotUpdateVisibility() +{ + if ( targetVisibility() ) + ++d->visibilityLevel; + else + --d->visibilityLevel; + + if ( !Private::foldVisibility && !Private::fadeVisibility ) + d->visibilityLevel = targetVisibility() ? Private::visibilityStepsTotal : 0; + else if ( !Private::fadeVisibility && d->visibilityLevel >= Private::visibilityFoldSteps ) + d->visibilityLevel = targetVisibility() ? Private::visibilityStepsTotal : Private::visibilityFoldSteps - 1; + else if ( !Private::foldVisibility && d->visibilityLevel <= Private::visibilityFoldSteps ) + d->visibilityLevel = targetVisibility() ? Private::visibilityFoldSteps + 1 : 0; + + if ( d->visibilityLevel >= Private::visibilityStepsTotal ) + { + d->visibilityLevel = Private::visibilityStepsTotal; + d->visibilityTimer.stop(); + } + else if ( d->visibilityLevel <= 0 ) + { + d->visibilityLevel = 0; + d->visibilityTimer.stop(); + setVisible( false ); + } + setHeight( 0 ); + repaint(); +} + +void Item::repaint() +{ + // if we're about to relayout, don't bother painting yet. + if ( d->layoutTimer.isActive() ) + return; + listView()->repaintItem( this ); +} + +void Item::relayout() +{ + scheduleLayout(); +} + +void Item::setup() +{ + KListViewItem::setup(); + slotLayoutItems(); +} + +void Item::setHeight( int ) +{ + int minHeight = 0; + for ( uint n = 0; n < components(); ++n ) + minHeight = QMAX( minHeight, component( n )->rect().height() ); + //kdDebug(14000) << k_funcinfo << "Height is " << minHeight << endl; + if ( Private::foldVisibility && d->visibilityTimer.isActive() ) + { + int vis = QMIN( d->visibilityLevel, Private::visibilityFoldSteps ); + minHeight = (minHeight * vis) / Private::visibilityFoldSteps; + } + KListViewItem::setHeight( minHeight ); +} + +int Item::width( const QFontMetrics &, const QListView *lv, int c ) const +{ + // Qt computes the itemRect from this. we want the whole item to be + // clickable, so we return the widest we could possibly be. + return lv->header()->sectionSize( c ); +} + +void Item::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) +{ + QPixmap back( width, height() ); + QPainter paint( &back ); + //KListViewItem::paintCell( &paint, cg, column, width, align ); + // PASTED FROM KLISTVIEWITEM: + // set the alternate cell background colour if necessary + QColorGroup _cg = cg; + if (isAlternate()) + if (listView()->viewport()->backgroundMode()==Qt::FixedColor) + _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground()); + else + _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground()); + // PASTED FROM QLISTVIEWITEM + { + QPainter *p = &paint; + + QListView *lv = listView(); + if ( !lv ) + return; + QFontMetrics fm( p->fontMetrics() ); + + // any text we render is done by the Components, not by this class, so make sure we've nothing to write + QString t; + + // removed text truncating code from Qt - we do that differently, further on + + int marg = lv->itemMargin(); + int r = marg; + // const QPixmap * icon = pixmap( column ); + + const BackgroundMode bgmode = lv->viewport()->backgroundMode(); + const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode ); + + if ( _cg.brush( crole ) != lv->colorGroup().brush( crole ) ) + p->fillRect( 0, 0, width, height(), _cg.brush( crole ) ); + else + { + // all copied from QListView::paintEmptyArea + + //lv->paintEmptyArea( p, QRect( 0, 0, width, height() ) ); + QStyleOption opt( lv->sortColumn(), 0 ); // ### hack; in 3.1, add a property in QListView and QHeader + QStyle::SFlags how = QStyle::Style_Default; + if ( lv->isEnabled() ) + how |= QStyle::Style_Enabled; + + lv->style().drawComplexControl( QStyle::CC_ListView, + p, lv, QRect( 0, 0, width, height() ), lv->colorGroup(), + how, QStyle::SC_ListView, QStyle::SC_None, + opt ); + } + + + + if ( isSelected() && + (column == 0 || lv->allColumnsShowFocus()) ) { + p->fillRect( r - marg, 0, width - r + marg, height(), + _cg.brush( QColorGroup::Highlight ) ); + // removed text pen setting code from Qt + } + + // removed icon drawing code from Qt + + // draw the tree gubbins + if ( multiLinesEnabled() && column == 0 && isOpen() && childCount() ) { + int textheight = fm.size( align, t ).height() + 2 * lv->itemMargin(); + textheight = QMAX( textheight, QApplication::globalStrut().height() ); + if ( textheight % 2 > 0 ) + textheight++; + if ( textheight < height() ) { + int w = lv->treeStepSize() / 2; + lv->style().drawComplexControl( QStyle::CC_ListView, p, lv, + QRect( 0, textheight, w + 1, height() - textheight + 1 ), _cg, + lv->isEnabled() ? QStyle::Style_Enabled : QStyle::Style_Default, + QStyle::SC_ListViewExpand, + (uint)QStyle::SC_All, QStyleOption( this ) ); + } + } + } + // END OF PASTE + + + //do you see a better way to tell the TextComponent we are selected ? - Olivier 2004-09-02 + if ( isSelected() ) + _cg.setColor(QColorGroup::Text , _cg.highlightedText() ); + + if ( Component *comp = component( column ) ) + comp->paint( &paint, _cg ); + paint.end(); + +#ifdef HAVE_XRENDER + QColor rgb = cg.base();//backgroundColor(); + float opac = 1.0; + if ( d->visibilityTimer.isActive() && Private::fadeVisibility ) + { + int vis = QMAX( d->visibilityLevel - Private::visibilityFoldSteps, 0 ); + opac = float(vis) / Private::visibilityFadeSteps; + } + opac *= opacity(); + const int alpha = 257 - int(opac * 257); + if ( alpha != 0 ) + { + XRenderColor clr = { alpha * rgb.red(), alpha * rgb.green(), alpha * rgb.blue(), alpha * 0xff }; + XRenderFillRectangle( back.x11Display(), PictOpOver, back.x11RenderHandle(), + &clr, 0, 0, width, height() ); + } +#endif + + p->drawPixmap( 0, 0, back ); +} + +void Item::componentAdded( Component *component ) +{ + ComponentBase::componentAdded( component ); + scheduleLayout(); +} + +void Item::componentRemoved( Component *component ) +{ + ComponentBase::componentRemoved( component ); + scheduleLayout(); +} + +void Item::componentResized( Component *component ) +{ + ComponentBase::componentResized( component ); + scheduleLayout(); +} + +} // END namespace ListView +} // END namespace UI +} // END namespace Kopete + +#include "kopetelistviewitem.moc" + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopetelistviewitem.h b/kopete/libkopete/ui/kopetelistviewitem.h new file mode 100644 index 00000000..5952c569 --- /dev/null +++ b/kopete/libkopete/ui/kopetelistviewitem.h @@ -0,0 +1,462 @@ +/* + kopetelistviewitem.h - Kopete's modular QListViewItems + + Copyright (c) 2005 by Engin AYDOGAN <engin@bzzzt.biz> + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETE_LISTVIEWITEM_H +#define KOPETE_LISTVIEWITEM_H + +#include <klistview.h> +#include <kopetecontact.h> + +#include <utility> +#include <qimage.h> + +class QPixmap; + +namespace Kopete { +namespace UI { +namespace ListView { + +class Component; + +class ComponentBase +{ +public: + ComponentBase(); + virtual ~ComponentBase() = 0; + + uint components(); + Component *component( uint n ); + Component *componentAt( const QPoint &pt ); + + /** Repaint this item */ + virtual void repaint() = 0; + /** Relayout this item */ + virtual void relayout() = 0; + + /** + * Get the tool tip string and rectangle for a tip request at position + * relativePos relative to this item. Queries the appropriate child component. + * + * @return a pair where the first element is the tooltip, and the second is + * the rectangle within the item for which the tip should be displayed. + */ + virtual std::pair<QString,QRect> toolTip( const QPoint &relativePos ); + +protected: + /** A child item has been added to this item */ + virtual void componentAdded( Component *component ); + /** A child item has been removed from this item */ + virtual void componentRemoved( Component *component ); + /** A child item has been resized */ + virtual void componentResized( Component *component ); + /** Remove all children */ + virtual void clear(); + + /** @internal animate items */ + void updateAnimationPosition( int p, int s ); +private: + class Private; + Private *d; + + // calls componentAdded and componentRemoved + friend class Component; +}; + +/** + * @author Richard Smith <kde@metafoo.co.uk> + */ +class ToolTipSource +{ +public: + /** + * Get the tooltip string and rect for a component + * + * @param component The component to get a tip for + * @param pt The point (relative to the list item) the mouse is at + * @param rect The tip will be removed when the mouse leaves this rect. + * Will initially be set to \p component's rect(). + */ + virtual QString operator() ( ComponentBase *component, const QPoint &pt, QRect &rect ) = 0; +}; + +/** + * This class represents a rectangular subsection of a ListItem. + * + * @author Richard Smith <kde@metafoo.co.uk> + */ +class Component : public ComponentBase +{ +protected: + Component( ComponentBase *parent ); +public: + virtual ~Component() = 0; + + /** + * Set the size and position of this item relative to the list view item. Should + * only be called by the containing item. + * @param rect the new rectangle this component will paint in, relative to the painter + * passed to the paint() function by the parent item. + */ + virtual void layout( const QRect &rect ); + + /** + * Paint this item, inside the rectangle returned by rect(). + * The default implementation calls paint on all children. + */ + virtual void paint( QPainter *painter, const QColorGroup &cg ); + + void repaint(); + void relayout(); + + /** + * @return the rect this component was allocated last time it was laid out + */ + QRect rect(); + /** + * Prevents this component to be drawn + */ + void hide(); + + /** + * Makes this component to be drawn + */ + void show(); + + bool isShown(); + bool isHidden(); + + /** + * Returns the smallest this component can become horizontally while still + * being useful. + */ + int minWidth(); + /** + * Returns the smallest this component can become vertically while still + * being useful. + */ + int minHeight(); + + /** + * Returns the width this component desires for a given @a height. By default + * this function returns minWidth(). + */ + virtual int widthForHeight( int height ); + /** + * Returns the height this component desires for a given @a width. By default + * this function returns minHeight(). + */ + virtual int heightForWidth( int width ); + + /** + * Set a tool tip source for this item. The tool tip source object is + * still owned by the caller, and must live for at least as long as + * this component. + */ + void setToolTipSource( ToolTipSource *source = 0 ); + + /** + * Get the tool tip string and rectangle for a tip request at position + * relativePos relative to this item. If a tooltip source is set, it will + * be used. Otherwise calls the base class. + * + * @return a pair where the first element is the tooltip, and the second is + * the rectangle within the item for which the tip should be displayed. + */ + std::pair<QString,QRect> toolTip( const QPoint &relativePos ); + + /** + * RTTI: Runtime Type Information + * Exactly the same as Qt's approach to identify types of + * QCanvasItems. + */ + + enum RttiValues { + Rtti_Component, Rtti_BoxComponent, Rtti_TextComponent, + Rtti_ImageComponent, Rtti_DisplayNameComponent, + Rtti_HSpacerComponent, Rtti_VSpacerComponent + }; + + static int RTTI; + virtual int rtti() const { return RTTI; } +protected: + /** + * Change the minimum width, in pixels, this component requires in order + * to be at all useful. Note: do not call this from your layout() function. + * @param width the minimum width + * @return true if the size has actually changed, false if it's been set to + * the existing values. if it returns true, you do not need to relayout, + * since the parent component will do that for you. + */ + bool setMinWidth( int width ); + /** + * Change the minimum height, in pixels, this component requires in order + * to be at all useful. Note: do not call this from your layout() function. + * @param height the minimum height + * @return true if the size has actually changed, false if it's been set to + * the existing values. If it returns true, you do not need to relayout, + * since the parent component will do that for you. + */ + bool setMinHeight( int height ); + + void componentAdded( Component *component ); + void componentRemoved( Component *component ); + +private: + // calls the three functions below + friend void ComponentBase::updateAnimationPosition( int p, int s ); + + // used for animation + void setRect( const QRect &rect ); + QRect startRect(); + QRect targetRect(); + + class Private; + Private *d; +}; + +class BoxComponent : public Component +{ +public: + enum Direction { Horizontal, Vertical }; + BoxComponent( ComponentBase *parent, Direction dir = Horizontal ); + ~BoxComponent(); + + void layout( const QRect &rect ); + + virtual int widthForHeight( int height ); + virtual int heightForWidth( int width ); + + static int RTTI; + virtual int rtti() const { return RTTI; } + +protected: + void componentAdded( Component *component ); + void componentRemoved( Component *component ); + void componentResized( Component *component ); + +private: + void calcMinSize(); + + class Private; + Private *d; +}; + +class TextComponent : public Component +{ +public: + TextComponent( ComponentBase *parent, const QFont &font = QFont(), const QString &text = QString::null ); + ~TextComponent(); + + QString text(); + void setText( const QString &text ); + + QFont font(); + void setFont( const QFont &font ); + + QColor color(); + void setColor( const QColor &color ); + void setDefaultColor(); + + int widthForHeight( int ); + + void paint( QPainter *painter, const QColorGroup &cg ); + + static int RTTI; + virtual int rtti() const { return RTTI; } + +private: + void calcMinSize(); + + class Private; + Private *d; +}; + +class ImageComponent : public Component +{ +public: + ImageComponent( ComponentBase *parent ); + ImageComponent( ComponentBase *parent, int minW, int minH ); + ~ImageComponent(); + + void setPixmap( const QPixmap &img, bool adjustSize = true); + QPixmap pixmap( void ); + + void paint( QPainter *painter, const QColorGroup &cg ); + + void scale( int w, int h, QImage::ScaleMode ); + static int RTTI; + virtual int rtti() const { return RTTI; } +private: + class Private; + Private *d; +}; + +/** + * ContactComponent + */ +class ContactComponent : public ImageComponent +{ +public: + ContactComponent( ComponentBase *parent, Kopete::Contact *contact, int iconSize); + ~ContactComponent(); + void updatePixmap(); + Kopete::Contact *contact(); + std::pair<QString,QRect> toolTip( const QPoint &relativePos ); +protected: + class Private; + Private *d; +}; + +/** + * SpacerComponent + */ +class SpacerComponent : public Component +{ +public: + SpacerComponent( ComponentBase *parent, int w, int h ); +}; + +/** + * DisplayNameComponent + */ + +class DisplayNameComponent : public BoxComponent +{ +public: + /** + * Constructor + */ + DisplayNameComponent( ComponentBase *parent ); + + /** + * Dtor + */ + ~DisplayNameComponent(); + void layout( const QRect& rect ); + + QString text(); + void setText( const QString& text ); + void setFont( const QFont& font ); + void setColor( const QColor& color ); + void setDefaultColor(); + static int RTTI; + virtual int rtti() const { return RTTI; } + /** + * reparse again for emoticon (call this when emoticon theme change) + */ + void redraw(); + +private: + class Private; + Private *d; +}; + +class HSpacerComponent : public Component +{ +public: + HSpacerComponent( ComponentBase *parent ); + int widthForHeight( int ); + + static int RTTI; + virtual int rtti() const { return RTTI; } +}; + +class VSpacerComponent : public Component +{ +public: + VSpacerComponent( ComponentBase *parent ); + int heightForWidth( int ); + + static int RTTI; + virtual int rtti() const { return RTTI; } +}; + +/** + * List-view item composed of Component items. Supports height-for-width, tooltips and + * some animation effects. + * + * @author Richard Smith <kde@metafoo.co.uk> + */ +class Item : public QObject, public KListViewItem, public ComponentBase +{ + Q_OBJECT +public: + Item( QListView *parent, QObject *owner = 0, const char *name = 0 ); + Item( QListViewItem *parent, QObject *owner = 0, const char *name = 0 ); + ~Item(); + + void repaint(); + void relayout(); + + void setup(); + virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ); + //TODO: startRename(...) + + float opacity(); + void setOpacity( float alpha ); + + bool targetVisibility(); + void setTargetVisibility( bool vis ); + + /** + * Turn on and off certain visual effects for all Items. + * @param animation whether changes to items should be animated. + * @param fading whether requests to setTargetVisibility should cause fading of items. + * @param folding whether requests to setTargetVisibility should cause folding of items. + */ + static void setEffects( bool animation, bool fading, bool folding ); + + int width( const QFontMetrics & fm, const QListView * lv, int c ) const; + + /** + * Show or hide this item in a clean way depending on whether it matches + * the current quick search + * @param match If true, show or hide the item as normal. If false, hide the item immediately. + */ + virtual void setSearchMatch( bool match ); + +protected: + void componentAdded( Component *component ); + void componentRemoved( Component *component ); + void componentResized( Component *component ); + + void setHeight( int ); + +private: + void initLVI(); + void recalcHeight(); + void scheduleLayout(); + +private slots: + void slotColumnResized(); + void slotLayoutItems(); + void slotLayoutAnimateItems(); + void slotUpdateVisibility(); + +private: + class Private; + Private *d; +}; + +} // END namespace ListView +} // END namespace UI +} // END namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopetelistviewsearchline.cpp b/kopete/libkopete/ui/kopetelistviewsearchline.cpp new file mode 100644 index 00000000..a71d86c0 --- /dev/null +++ b/kopete/libkopete/ui/kopetelistviewsearchline.cpp @@ -0,0 +1,138 @@ +/* + kopetelistviewsearchline.cpp - a widget for performing quick searches on Kopete::ListViews + Based on code from KMail, copyright (c) 2004 Till Adam <adam@kde.org> + + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetelistviewsearchline.h" +#include "kopetelistviewitem.h" +#include "kopetelistview.h" + +namespace Kopete { +namespace UI { +namespace ListView { + +SearchLine::SearchLine( QWidget *parent, ListView *listView, const char *name ) + : KListViewSearchLine( parent, listView, name ) +{ +} + +SearchLine::SearchLine(QWidget *parent, const char *name) + : KListViewSearchLine( parent, 0, name ) +{ +} + +SearchLine::~SearchLine() +{ +} + + +void SearchLine::updateSearch( const QString &s ) +{ + // we copy a huge chunk of code here simply in order to override + // the way items are shown/hidden. KSearchLine rudely + // calls setVisible() on items with no way to customise this behaviour. + + //BEGIN code from KSearchLine::updateSearch + if( !listView() ) + return; + + search = s.isNull() ? text() : s; + + // If there's a selected item that is visible, make sure that it's visible + // when the search changes too (assuming that it still matches). + + QListViewItem *currentItem = 0; + + switch( listView()->selectionMode() ) + { + case KListView::NoSelection: + break; + case KListView::Single: + currentItem = listView()->selectedItem(); + break; + default: + for( QListViewItemIterator it(listView(), QListViewItemIterator::Selected | QListViewItemIterator::Visible); + it.current() && !currentItem; ++it ) + { + if( listView()->itemRect( it.current() ).isValid() ) + currentItem = it.current(); + } + } + + if( keepParentsVisible() ) + checkItemParentsVisible( listView()->firstChild() ); + else + checkItemParentsNotVisible(); + + if( currentItem ) + listView()->ensureItemVisible( currentItem ); + //END code from KSearchLine::updateSearch +} + +void SearchLine::checkItemParentsNotVisible() +{ + //BEGIN code from KSearchLine::checkItemParentsNotVisible + QListViewItemIterator it( listView() ); + for( ; it.current(); ++it ) + { + QListViewItem *item = it.current(); + if( itemMatches( item, search ) ) + setItemVisible( item, true ); + else + setItemVisible( item, false ); + } + //END code from KSearchLine::checkItemParentsNotVisible +} + +bool SearchLine::checkItemParentsVisible( QListViewItem *item ) +{ + //BEGIN code from KSearchLine::checkItemParentsVisible + bool visible = false; + for( ; item; item = item->nextSibling() ) { + if( ( item->firstChild() && checkItemParentsVisible( item->firstChild() ) ) || + itemMatches( item, search ) ) + { + setItemVisible( item, true ); + // OUCH! this operation just became exponential-time. + // however, setting an item visible sets all its descendents + // visible too, which we definitely don't want. + // plus, in Kopete the nesting is never more than 2 deep, + // so this really just doubles the runtime, if that. + // this still can be done in O(n) time by a mark-set process, + // but that's overkill in our case. + checkItemParentsVisible( item->firstChild() ); + visible = true; + } + else + setItemVisible( item, false ); + } + return visible; + //END code from KSearchLine::checkItemParentsVisible +} + +void SearchLine::setItemVisible( QListViewItem *it, bool b ) +{ + if( Item *item = dynamic_cast<Item*>( it ) ) + item->setSearchMatch( b ); + else + it->setVisible( b ); +} + +} // namespace ListView +} // namespace UI +} // namespace Kopete + +#include "kopetelistviewsearchline.moc" diff --git a/kopete/libkopete/ui/kopetelistviewsearchline.h b/kopete/libkopete/ui/kopetelistviewsearchline.h new file mode 100644 index 00000000..a453b844 --- /dev/null +++ b/kopete/libkopete/ui/kopetelistviewsearchline.h @@ -0,0 +1,66 @@ +/* + kopetelistviewsearchline.h - a widget for performing quick searches of Kopete::ListViews + + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETELISTVIEWSEARCHLINE_H +#define KOPETELISTVIEWSEARCHLINE_H + +#include <klistviewsearchline.h> + +namespace Kopete { +namespace UI { +namespace ListView { + +class ListView; + +class SearchLine : public KListViewSearchLine +{ + Q_OBJECT +public: + /** + * Constructs a SearchLine with \a listView being the + * ListView to be filtered. + * + * If \a listView is null then the widget will be disabled until a listview + * is set with setListView(). + */ + SearchLine( QWidget *parent, ListView *listView = 0, const char *name = 0 ); + /** + * Constructs a SearchLine without any ListView to filter. The + * KListView object has to be set later with setListView(). + */ + SearchLine(QWidget *parent, const char *name); + /** + * Destroys the SearchLine. + */ + ~SearchLine(); + + void updateSearch( const QString &s ); + +protected: + virtual void checkItemParentsNotVisible(); + virtual bool checkItemParentsVisible( QListViewItem *it ); + virtual void setItemVisible( QListViewItem *it, bool visible ); + +private: + QString search; +}; + +} // end namespace ListView +} // end namespace UI +} // end namespace Kopete + +#endif diff --git a/kopete/libkopete/ui/kopetepassworddialog.ui b/kopete/libkopete/ui/kopetepassworddialog.ui new file mode 100644 index 00000000..7ba4dff9 --- /dev/null +++ b/kopete/libkopete/ui/kopetepassworddialog.ui @@ -0,0 +1,109 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>KopetePasswordDialog</class> +<author>Olivier Goffart</author> +<widget class="QWidget"> + <property name="name"> + <cstring>KopetePasswordDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>472</width> + <height>117</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_image</cstring> + </property> + </widget> + <widget class="KActiveLabel"> + <property name="name"> + <cstring>m_text</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="textFormat"> + <enum>RichText</enum> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>&Password:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_password</cstring> + </property> + </widget> + <widget class="KPasswordEdit"> + <property name="name"> + <cstring>m_password</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_save_passwd</cstring> + </property> + <property name="text"> + <string>&Remember password</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<tabstops> + <tabstop>m_password</tabstop> + <tabstop>m_save_passwd</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kopete/libkopete/ui/kopetepasswordwidget.cpp b/kopete/libkopete/ui/kopetepasswordwidget.cpp new file mode 100644 index 00000000..2345f103 --- /dev/null +++ b/kopete/libkopete/ui/kopetepasswordwidget.cpp @@ -0,0 +1,132 @@ +/* + kopetepasswordwidget.cpp - widget for modifying a Kopete::Password + + Copyright (c) 2003 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetepasswordwidget.h" +#include "kopetepassword.h" + +#include <kpassdlg.h> + +#include <qcheckbox.h> + +class Kopete::UI::PasswordWidget::Private +{ +public: + uint maxLength; +}; + +Kopete::UI::PasswordWidget::PasswordWidget( QWidget *parent, const char *name, Kopete::Password *from ) + : KopetePasswordWidgetBase( parent, name ), d( new Private ) +{ + load( from ); +} + +Kopete::UI::PasswordWidget::~PasswordWidget() +{ + delete d; +} + +void Kopete::UI::PasswordWidget::load( Kopete::Password *source ) +{ + disconnect( mRemembered, SIGNAL( stateChanged( int ) ), this, SLOT( slotRememberChanged() ) ); + disconnect( mPassword, SIGNAL( textChanged( const QString & ) ), this, SIGNAL( changed() ) ); + disconnect( mRemembered, SIGNAL( stateChanged( int ) ), this, SIGNAL( changed() ) ); + + if ( source && source->remembered() ) + { + mRemembered->setTristate(); + mRemembered->setNoChange(); + source->requestWithoutPrompt( this, SLOT( receivePassword( const QString & ) ) ); + } + else + { + mRemembered->setTristate( false ); + mRemembered->setChecked( false ); + } + + if ( source ) + d->maxLength = source->maximumLength(); + else + d->maxLength = 0; + + mPassword->setEnabled( false ); + + connect( mRemembered, SIGNAL( stateChanged( int ) ), this, SLOT( slotRememberChanged() ) ); + connect( mPassword, SIGNAL( textChanged( const QString & ) ), this, SIGNAL( changed() ) ); + connect( mRemembered, SIGNAL( stateChanged( int ) ), this, SIGNAL( changed() ) ); + + emit changed(); +} + +void Kopete::UI::PasswordWidget::slotRememberChanged() +{ + mRemembered->setTristate( false ); + mPassword->setEnabled( mRemembered->isChecked() ); +} + +void Kopete::UI::PasswordWidget::receivePassword( const QString &pwd ) +{ + // pwd == null could mean user declined to open wallet + // don't uncheck the remembered field in this case. + if ( !pwd.isNull() && mRemembered->state() == QButton::NoChange ) + { + mRemembered->setChecked( true ); + setPassword( pwd ); + } +} + +void Kopete::UI::PasswordWidget::save( Kopete::Password *target ) +{ + if ( !target || mRemembered->state() == QButton::NoChange ) + return; + + if ( mRemembered->isChecked() ) + target->set( password() ); + else + target->set(); +} + +bool Kopete::UI::PasswordWidget::validate() +{ + if ( !mRemembered->isChecked() ) return true; + if ( d->maxLength == 0 ) return true; + return password().length() <= d->maxLength; +} + +QString Kopete::UI::PasswordWidget::password() const +{ + return QString::fromLocal8Bit( mPassword->password() ); +} + +bool Kopete::UI::PasswordWidget::remember() const +{ + return mRemembered->state() == QButton::On; +} + +void Kopete::UI::PasswordWidget::setPassword( const QString &pass ) +{ + // switch out of 'waiting for wallet' mode if we're in it + mRemembered->setTristate( false ); + + // fill in the password text + mPassword->erase(); + mPassword->insert( pass ); + mPassword->setEnabled( remember() ); +} + +#include "kopetepasswordwidget.moc" + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopetepasswordwidget.h b/kopete/libkopete/ui/kopetepasswordwidget.h new file mode 100644 index 00000000..b1c51a39 --- /dev/null +++ b/kopete/libkopete/ui/kopetepasswordwidget.h @@ -0,0 +1,109 @@ +/* + kopetepasswordwidget.cpp - widget for editing a Kopete::Password + + Copyright (c) 2003 by Richard Smith <kde@metafoo.co.uk> + + Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETEPASSWORDWIDGET_H +#define KOPETEPASSWORDWIDGET_H + +#include "kopetepasswordwidgetbase.h" +#include "kopete_export.h" + +namespace Kopete +{ + +class Password; + +namespace UI +{ + +/** + * @author Richard Smith <kde@metafoo.co.uk> + * This widget displays an editable password, including the Remember password checkbox. + * @todo This is NOT BC yet : it derives from a uic-generated class + */ +class KOPETE_EXPORT PasswordWidget : public KopetePasswordWidgetBase +{ + Q_OBJECT + +public: + /** + * Creates a Kopete::PasswordWidget. + * @param parent The widget to nest this one inside + * @param name The name of this QObject + * @param from The password to load the data for this widget from, or 0 if none + */ + PasswordWidget( QWidget *parent, const char *name = 0, Kopete::Password *from = 0 ); + ~PasswordWidget(); + + /** + * Loads the information stored in source into the widget + */ + void load( Kopete::Password *source ); + /** + * Saves the information in the widget into target + */ + void save( Kopete::Password *target ); + + /** + * Returns true if the information in the widget is valid, false if it is not. + * Currently the only way this can fail is if the password is too long. + * @todo this should return an enum of failures. + */ + bool validate(); + + /** + * Returns the string currently in the input box in the widget + */ + QString password() const; + /** + * Returns a boolean indicating whether the Remember Password checkbox is checked. + * Result is undefined if the Remember Password field is in the 'no change' state + * because the user has not (yet) opened the wallet. + */ + bool remember() const; + + /** + * Set the password stored in the widget. + * @param pass The text to place in the password field. + */ + void setPassword( const QString &pass ); + +signals: + /** + * Emitted when the information stored in this widget changes + */ + void changed(); + +public slots: + /** @internal */ + void receivePassword( const QString & ); + +private slots: + void slotRememberChanged(); + +private: + class Private; + Private *d; +}; + +} + +} + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/kopetepasswordwidgetbase.ui b/kopete/libkopete/ui/kopetepasswordwidgetbase.ui new file mode 100644 index 00000000..5f6b665a --- /dev/null +++ b/kopete/libkopete/ui/kopetepasswordwidgetbase.ui @@ -0,0 +1,98 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>KopetePasswordWidgetBase</class> +<author>Richard Smith <kde@metafoo.co.uk></author> +<widget class="QWidget"> + <property name="name"> + <cstring>KopetePasswordWidgetBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>497</width> + <height>50</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>mRemembered</cstring> + </property> + <property name="text"> + <string>Remember password</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Check this and enter your password below if you would like your password to be stored in your wallet, so Kopete does not have to ask you for it each time it is needed.</string> + </property> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Password:</string> + </property> + </widget> + <widget class="KPasswordEdit" row="1" column="2"> + <property name="name"> + <cstring>mPassword</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>Enter your password here.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter your password here. If you would rather not save your password, uncheck the Remember password checkbox above; you will then be prompted for your password whenever it is needed.</string> + </property> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>mRemembered</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpassdlg.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/kopetestdaction.cpp b/kopete/libkopete/ui/kopetestdaction.cpp new file mode 100644 index 00000000..e6731485 --- /dev/null +++ b/kopete/libkopete/ui/kopetestdaction.cpp @@ -0,0 +1,129 @@ +/* + kopetestdaction.cpp - Kopete Standard Actionds + + Copyright (c) 2001-2002 by Ryan Cumming <ryan@kde.org> + Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org> + + Kopete (c) 2001-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetestdaction.h" + +#include <qapplication.h> + +#include <kdebug.h> +#include <kdeversion.h> +#include <kguiitem.h> +#include <klocale.h> +#include <ksettings/dialog.h> +#include <kstdaction.h> +#include <kstdguiitem.h> +#include <kwin.h> +#include <kcmultidialog.h> + +#include "kopetecontactlist.h" +#include "kopetegroup.h" +#include "kopeteuiglobal.h" + +KSettings::Dialog *KopetePreferencesAction::s_settingsDialog = 0L; + +KopetePreferencesAction::KopetePreferencesAction( KActionCollection *parent, const char *name ) +#if KDE_IS_VERSION( 3, 3, 90 ) +: KAction( KStdGuiItem::configure(), 0, 0, 0, parent, name ) +#else +: KAction( KGuiItem( i18n( "&Configure Kopete..." ), + QString::fromLatin1( "configure" ) ), 0, 0, 0, parent, name ) +#endif +{ + connect( this, SIGNAL( activated() ), this, SLOT( slotShowPreferences() ) ); +} + +KopetePreferencesAction::~KopetePreferencesAction() +{ +} + +void KopetePreferencesAction::slotShowPreferences() +{ + // FIXME: Use static deleter - Martijn + if ( !s_settingsDialog ) + s_settingsDialog = new KSettings::Dialog( KSettings::Dialog::Static, Kopete::UI::Global::mainWidget() ); + s_settingsDialog->show(); + + s_settingsDialog->dialog()->raise(); + + KWin::activateWindow( s_settingsDialog->dialog()->winId() ); +} + +KAction * KopeteStdAction::preferences( KActionCollection *parent, const char *name ) +{ + return new KopetePreferencesAction( parent, name ); +} + +KAction * KopeteStdAction::chat( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "Start &Chat..." ), QString::fromLatin1( "mail_generic" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::sendMessage( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "&Send Single Message..." ), QString::fromLatin1( "mail_generic" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::contactInfo( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "User &Info" ), QString::fromLatin1( "messagebox_info" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::sendFile( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "Send &File..." ), QString::fromLatin1( "attach" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::viewHistory( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "View &History..." ), QString::fromLatin1( "history" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::addGroup( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "&Create Group..." ), QString::fromLatin1( "folder" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::changeMetaContact( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "Cha&nge Meta Contact..." ), QString::fromLatin1( "move" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::deleteContact( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "&Delete Contact" ), QString::fromLatin1( "delete_user" ), Qt::Key_Delete, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::changeAlias( const QObject *recvr, const char *slot, QObject *parent, const char *name ) +{ + return new KAction( i18n( "Change A&lias..." ), QString::fromLatin1( "signature" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::blockContact( const QObject *recvr, const char *slot, QObject* parent, const char *name ) +{ + return new KAction( i18n( "&Block Contact" ), QString::fromLatin1( "player_pause" ), 0, recvr, slot, parent, name ); +} + +KAction * KopeteStdAction::unblockContact( const QObject *recvr, const char *slot, QObject* parent, const char *name ) +{ + return new KAction( i18n( "Un&block Contact" ), QString::fromLatin1( "player_play" ), 0, recvr, slot, parent, name ); +} + +#include "kopetestdaction.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/kopetestdaction.h b/kopete/libkopete/ui/kopetestdaction.h new file mode 100644 index 00000000..8f06d296 --- /dev/null +++ b/kopete/libkopete/ui/kopetestdaction.h @@ -0,0 +1,119 @@ +/* + kopetestdaction.h - Kopete Standard Actionds + + Copyright (c) 2001-2002 by Ryan Cumming <bodnar42@phalynx.dhs.org> + Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETESTDACTION_H +#define KOPETESTDACTION_H + +#undef KDE_NO_COMPAT +#include <kaction.h> +#include <qobject.h> + +#include "kopete_export.h" + +/** + * @author Ryan Cumming <bodnar42@phalynx.dhs.org> + */ +class KOPETE_EXPORT KopeteStdAction +{ +public: + /** + * Standard action to start a chat + */ + static KAction *chat( const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0 ); + /** + * Standard action to send a single message + */ + static KAction *sendMessage(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to open a user info dialog + */ + static KAction *contactInfo(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to open a history dialog or something similar + */ + static KAction *viewHistory(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to initiate sending a file to a contact + */ + static KAction *sendFile(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to change a contacts @ref Kopete::MetaContact + */ + static KAction *changeMetaContact(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to add a group + */ + static KAction *addGroup(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to delete a contact + */ + static KAction *deleteContact(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to change a contact alias/nickname in your contactlist + */ + static KAction *changeAlias(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to block a contact + */ + static KAction *blockContact(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + /** + * Standard action to unblock a contact + */ + static KAction *unblockContact(const QObject *recvr, const char *slot, + QObject* parent, const char *name = 0); + + /** + * Return an action to change the Kopete preferences. + * + * The object has no signal/slot, the prefs are automatically shown + */ + static KAction *preferences(KActionCollection *parent, const char *name = 0); +}; + + +namespace KSettings +{ + class Dialog; +} + +class KOPETE_EXPORT KopetePreferencesAction : public KAction +{ + Q_OBJECT + + public: + KopetePreferencesAction( KActionCollection *parent, const char *name = 0 ); + ~KopetePreferencesAction(); + + protected slots: + void slotShowPreferences(); + private: + static KSettings::Dialog *s_settingsDialog; +}; + +#endif +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/kopeteview.cpp b/kopete/libkopete/ui/kopeteview.cpp new file mode 100644 index 00000000..91f1fa9c --- /dev/null +++ b/kopete/libkopete/ui/kopeteview.cpp @@ -0,0 +1,52 @@ +/* + kopeteview.cpp - View Abstract Class + + Copyright (c) 2003 by Jason Keirstead + Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org> + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopeteview.h" + +KopeteView::KopeteView( Kopete::ChatSession *manager, Kopete::ViewPlugin *plugin ) + : m_manager(manager), m_plugin(plugin) +{ +} + +Kopete::ChatSession *KopeteView::msgManager() const +{ + return m_manager; +} + +void KopeteView::clear() +{ + //Do nothing +} + +void KopeteView::appendMessages(QValueList<Kopete::Message> msgs) +{ + QValueList<Kopete::Message>::iterator it; + for ( it = msgs.begin(); it != msgs.end(); ++it ) + { + appendMessage(*it); + } + +} + +Kopete::ViewPlugin *KopeteView::plugin() +{ + return m_plugin; +} + +KopeteView::~ KopeteView( ) +{ +} diff --git a/kopete/libkopete/ui/kopeteview.h b/kopete/libkopete/ui/kopeteview.h new file mode 100644 index 00000000..47320546 --- /dev/null +++ b/kopete/libkopete/ui/kopeteview.h @@ -0,0 +1,176 @@ +/* + kopeteview.h - View Manager + + Copyright (c) 2003 by Jason Keirstead <jason@keirstead.org> + Copyright (c) 2004 by Matt Rogers <matt.rogers@kdemail.net> + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + + +#ifndef KOPETEVIEW_H +#define KOPETEVIEW_H + +#include "kopetemessage.h" +#include <qvaluelist.h> +#include "kopete_export.h" + +namespace Kopete +{ + class ViewPlugin; +} + +/** + * @author Jason Keirstead + * + * Abstract parent class for all types of views used for messaging.These view objects + * are provided by a @ref Kopete::ViewPlugin + * + * @see Kopete::ViewPlugin + */ +class KOPETE_EXPORT KopeteView +{ + public: + /** + * constructor + */ + KopeteView( Kopete::ChatSession *manager, Kopete::ViewPlugin *parent ); + virtual ~KopeteView(); + + /** + * @brief Returns the message currently in the edit area + * @return The Kopete::Message object containing the message + */ + virtual Kopete::Message currentMessage() = 0; + /** + * Set the message that the view is currently editing. + * @param newMessage The Kopete::Message object containing the message to be edited. + */ + virtual void setCurrentMessage( const Kopete::Message &newMessage ) = 0; + + /** + * @brief Get the message manager + * @return The Kopete::ChatSession that the view is in communication with. + */ + Kopete::ChatSession *msgManager() const; + + /** + * @brief add a message to the view + * + * The message gets added at the end of the view and is automatically + * displayed. Classes that inherit from KopeteView should make this a slot. + */ + virtual void appendMessage( Kopete::Message & ) = 0; + + /** + * @brief append multiple messages to the view + * + * This function does the same thing as the above function but + * can be reimplemented if it is faster to apend several messages + * in the same time. + * + * The default implementation just call @ref appendMessage() X times + */ + virtual void appendMessages( QValueList<Kopete::Message> ); + + /** + * @brief Raises the view above other windows + * @param activate change the focus to the window + */ + virtual void raise(bool activate = false) = 0; + + /** + * @brief Clear the buffer + */ + virtual void clear(); + + /** + * @brief Make the view visible + * + * Makes the view visible if it is currently hidden. + */ + virtual void makeVisible() = 0; + + /** + * @brief Close this view + */ + virtual bool closeView( bool force = false ) = 0; + + /** + * @brief Get the current visibility of the view + * @return Whether the view is visible or not. + */ + virtual bool isVisible() = 0; + + /** + * @brief Get the view widget + * + * Can be reimplemented to return this if derived object is a widget + */ + virtual QWidget *mainWidget() = 0; + + /** + * @brief Inform the view the message was sent successfully + * + * This should be reimplemented as a SLOT in any derived objects + */ + virtual void messageSentSuccessfully() = 0; + + /** + * @brief Register a handler for the context menu + * + * Plugins should call this slot at view creation to register + * themselves as handlers for the context menu of this view. Plugins + * can attach to the viewCreated signal of KopeteMessageManagerFactory + * to know when views are created. + * + * A view does not need to implement this method unless they have context + * menus that can be extended + * + * @param target A target QObject for the contextMenuEvent signal of the view + * @param slot A slot that matches the signature ( QString&, KPopupMenu *) + */ + virtual void registerContextMenuHandler( QObject *target, const char*slot ){ Q_UNUSED(target); Q_UNUSED(slot); }; + + /** + * @brief Register a handler for the tooltip + * + * Plugins should call this slot at view creation to register + * themselves as handlers for the tooltip of this view. Plugins + * can attach to the viewCreated signal of KopeteMessageManagerFactory + * to know when views are created. + * + * A view does not need to impliment this method unless it has the ability + * to show tooltips + * + * @param target A target QObject for the contextMenuEvent signal of the view + * @param slot A slot that matches the signature ( QString&, KPopupMenu *) + */ + virtual void registerTooltipHandler( QObject *target, const char*slot ){ Q_UNUSED(target); Q_UNUSED(slot); }; + + /** + * @brief Returns the Kopete::ViewPlugin responsible for this view + * + * KopeteView objects are created by plugins. This returns a pointer to the plugin + * that created this view. You can use this to infer other information on this view + * and it's capabilities. + */ + Kopete::ViewPlugin *plugin(); + + protected: + /** + * a pointer to the Kopete::ChatSession given in the constructor + */ + Kopete::ChatSession *m_manager; + Kopete::ViewPlugin *m_plugin; +}; + +#endif diff --git a/kopete/libkopete/ui/kopeteviewplugin.cpp b/kopete/libkopete/ui/kopeteviewplugin.cpp new file mode 100644 index 00000000..b358e547 --- /dev/null +++ b/kopete/libkopete/ui/kopeteviewplugin.cpp @@ -0,0 +1,28 @@ +/* + kopeteviewplugin.cpp - View Manager + + Copyright (c) 2005 by Jason Keirstead <jason@keirstead.org> + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopeteviewplugin.h" + +Kopete::ViewPlugin::ViewPlugin( KInstance *instance, QObject *parent, const char *name ) : + Kopete::Plugin( instance, parent, name ) +{ + +} + +void Kopete::ViewPlugin::aboutToUnload() +{ + emit readyForUnload(); +} diff --git a/kopete/libkopete/ui/kopeteviewplugin.h b/kopete/libkopete/ui/kopeteviewplugin.h new file mode 100644 index 00000000..e7797d56 --- /dev/null +++ b/kopete/libkopete/ui/kopeteviewplugin.h @@ -0,0 +1,59 @@ +/* + kopeteviewplugin.h - View Manager + + Copyright (c) 2005 by Jason Keirstead <jason@keirstead.org> + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETEVIEWPLUGIN_H +#define KOPETEVIEWPLUGIN_H + +#include "kopeteplugin.h" + +class KopeteView; + +namespace Kopete +{ + +class ChatSession; + +/** + * @author Jason Keirstead + * + * @brief Factory plugin for creating KopeteView objects. + * + * Kopete ships with two of these currently, a Chat Window view plugin, and + * an Email Window view plugin. + * + */ +class KOPETE_EXPORT ViewPlugin : public Plugin +{ + public: + /** + * @brief Create and initialize the plugin + */ + ViewPlugin( KInstance *instance, QObject *parent = 0L, const char *name = 0L ); + + /** + * @brief Creates a view to be associated with the passed in session + */ + virtual KopeteView *createView( ChatSession * /*session*/ ){ return 0L; }; + + /** + * @brief Reimplemented from Kopete::Plugin + */ + virtual void aboutToUnload(); +}; + +} + +#endif diff --git a/kopete/libkopete/ui/kopetewidgets.cpp b/kopete/libkopete/ui/kopetewidgets.cpp new file mode 100644 index 00000000..093ee48e --- /dev/null +++ b/kopete/libkopete/ui/kopetewidgets.cpp @@ -0,0 +1,131 @@ +/** +* This file was autogenerated by makekdewidgets. Any changes will be lost! +* The generated code in this file is licensed under the same license that the +* input file. +*/ +#include <qwidgetplugin.h> + +#include <kinstance.h> +#include <addressbooklinkwidget.h> +#include <kopetelistview.h> +#include <kopetelistviewsearchline.h> +#ifndef EMBED_IMAGES +#include <kstandarddirs.h> +#endif + +class KopeteWidgets : public QWidgetPlugin +{ +public: + KopeteWidgets(); + + virtual ~KopeteWidgets(); + + virtual QStringList keys() const + { + QStringList result; + for (WidgetInfos::ConstIterator it = m_widgets.begin(); it != m_widgets.end(); ++it) + result << it.key(); + return result; + } + + virtual QWidget *create(const QString &key, QWidget *parent = 0, const char *name = 0); + + virtual QIconSet iconSet(const QString &key) const + { +#ifdef EMBED_IMAGES + QPixmap pix(m_widgets[key].iconSet); +#else + QPixmap pix(locate( "data", + QString::fromLatin1("kopetewidgets/pics/") + m_widgets[key].iconSet)); +#endif + return QIconSet(pix); + } + + virtual bool isContainer(const QString &key) const { return m_widgets[key].isContainer; } + + virtual QString group(const QString &key) const { return m_widgets[key].group; } + + virtual QString includeFile(const QString &key) const { return m_widgets[key].includeFile; } + + virtual QString toolTip(const QString &key) const { return m_widgets[key].toolTip; } + + virtual QString whatsThis(const QString &key) const { return m_widgets[key].whatsThis; } +private: + struct WidgetInfo + { + QString group; +#ifdef EMBED_IMAGES + QPixmap iconSet; +#else + QString iconSet; +#endif + QString includeFile; + QString toolTip; + QString whatsThis; + bool isContainer; + }; + typedef QMap<QString, WidgetInfo> WidgetInfos; + WidgetInfos m_widgets; +}; +KopeteWidgets::KopeteWidgets() +{ + WidgetInfo widget; + + widget.group = QString::fromLatin1("Input (Kopete)"); +#ifdef EMBED_IMAGES + widget.iconSet = QPixmap(kopete__ui__addressbooklinkwidget_xpm); +#else + widget.iconSet = QString::fromLatin1("kopete__ui__addressbooklinkwidget.png"); +#endif + widget.includeFile = QString::fromLatin1("addressbooklinkwidget.h"); + widget.toolTip = QString::fromLatin1("Address Book Link Widget (Kopete)"); + widget.whatsThis = QString::fromLatin1("KABC::Addressee display/selector"); + widget.isContainer = false; + m_widgets.insert(QString::fromLatin1("Kopete::UI::AddressBookLinkWidget"), widget); + + widget.group = QString::fromLatin1("Views (Kopete)"); +#ifdef EMBED_IMAGES + widget.iconSet = QPixmap(kopete__ui__listview__listview_xpm); +#else + widget.iconSet = QString::fromLatin1("kopete__ui__listview__listview.png"); +#endif + widget.includeFile = QString::fromLatin1("kopetelistview.h"); + widget.toolTip = QString::fromLatin1("List View (Kopete)"); + widget.whatsThis = QString::fromLatin1("A component capable list view widget."); + widget.isContainer = false; + m_widgets.insert(QString::fromLatin1("Kopete::UI::ListView::ListView"), widget); + + widget.group = QString::fromLatin1("Input (Kopete)"); +#ifdef EMBED_IMAGES + widget.iconSet = QPixmap(kopete__ui__listview__searchline_xpm); +#else + widget.iconSet = QString::fromLatin1("kopete__ui__listview__searchline.png"); +#endif + widget.includeFile = QString::fromLatin1("kopetelistviewsearchline.h"); + widget.toolTip = QString::fromLatin1("List View Search Line (Kopete)"); + widget.whatsThis = QString::fromLatin1("Search line able to use Kopete custom list View."); + widget.isContainer = false; + m_widgets.insert(QString::fromLatin1("Kopete::UI::ListView::SearchLine"), widget); + + new KInstance("kopetewidgets"); +} +KopeteWidgets::~KopeteWidgets() +{ + +} +QWidget *KopeteWidgets::create(const QString &key, QWidget *parent, const char *name) +{ + + if (key == QString::fromLatin1("Kopete::UI::AddressBookLinkWidget")) + return new Kopete::UI::AddressBookLinkWidget(parent, name); + + if (key == QString::fromLatin1("Kopete::UI::ListView::ListView")) + return new Kopete::UI::ListView::ListView(parent, name); + + if (key == QString::fromLatin1("Kopete::UI::ListView::SearchLine")) + return new Kopete::UI::ListView::SearchLine(parent, 0, name); + + return 0; +} +KDE_Q_EXPORT_PLUGIN(KopeteWidgets) + diff --git a/kopete/libkopete/ui/metacontactselectorwidget.cpp b/kopete/libkopete/ui/metacontactselectorwidget.cpp new file mode 100644 index 00000000..d9c75308 --- /dev/null +++ b/kopete/libkopete/ui/metacontactselectorwidget.cpp @@ -0,0 +1,287 @@ +/* + MetaContactSelectorWidget + + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qcheckbox.h> +#include <qlabel.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include <qvbox.h> +#include <qimage.h> +#include <qpixmap.h> +#include <qpainter.h> +#include <qlayout.h> +#include <qvaluelist.h> + +#include <kapplication.h> +#include <kconfig.h> +#include <klocale.h> +#include <kiconloader.h> + +#include <kdeversion.h> +#include <kinputdialog.h> +#include <kpushbutton.h> +#include <kactivelabel.h> +#include <kdebug.h> +#include <klistview.h> +#include <klistviewsearchline.h> + +#include "kopetelistview.h" +#include "kopetelistviewsearchline.h" +#include "kopetecontactlist.h" +#include "kopetemetacontact.h" +#include "metacontactselectorwidget_base.h" +#include "metacontactselectorwidget.h" + +using namespace Kopete::UI::ListView; + +namespace Kopete +{ +namespace UI +{ + +class MetaContactSelectorWidgetLVI::Private +{ +public: + Kopete::MetaContact *metaContact; + ImageComponent *metaContactPhoto; + ImageComponent *metaContactIcon; + DisplayNameComponent *nameText; + TextComponent *extraText; + BoxComponent *contactIconBox; + BoxComponent *spacerBox; + int photoSize; + int contactIconSize; +}; + + +MetaContactSelectorWidgetLVI::MetaContactSelectorWidgetLVI(Kopete::MetaContact *mc, QListView *parent, QObject *owner, const char *name) : Kopete::UI::ListView::Item(parent, owner, name) , d( new Private() ) +{ + d->metaContact = mc; + d->photoSize = 60; + + connect( d->metaContact, SIGNAL( photoChanged() ), + SLOT( slotPhotoChanged() ) ); + connect( d->metaContact, SIGNAL( displayNameChanged(const QString&, const QString&) ), + SLOT( slotDisplayNameChanged() ) ); + buildVisualComponents(); +} + +Kopete::MetaContact* MetaContactSelectorWidgetLVI::metaContact() +{ + return d->metaContact; +} + +void MetaContactSelectorWidgetLVI::slotDisplayNameChanged() +{ + if ( d->nameText ) + { + d->nameText->setText( d->metaContact->displayName() ); + + // delay the sort if we can + if ( ListView::ListView *lv = dynamic_cast<ListView::ListView *>( listView() ) ) + lv->delayedSort(); + else + listView()->sort(); + } +} + +QString MetaContactSelectorWidgetLVI::text ( int /* column */ ) const +{ + return d->metaContact->displayName(); +} + +void MetaContactSelectorWidgetLVI::slotPhotoChanged() +{ + QPixmap photoPixmap; + QImage photoImg = d->metaContact->photo(); + if ( !photoImg.isNull() && (photoImg.width() > 0) && (photoImg.height() > 0) ) + { + int photoSize = d->photoSize; + + photoImg = photoImg.smoothScale( photoSize, photoSize, QImage::ScaleMin ) ; + + // draw a 1 pixel black border + photoPixmap = photoImg; + QPainter p(&photoPixmap); + p.setPen(Qt::black); + p.drawLine(0, 0, photoPixmap.width()-1, 0); + p.drawLine(0, photoPixmap.height()-1, photoPixmap.width()-1, photoPixmap.height()-1); + p.drawLine(0, 0, 0, photoPixmap.height()-1); + p.drawLine(photoPixmap.width()-1, 0, photoPixmap.width()-1, photoPixmap.height()-1); + } + else + { + // if no photo use the smilie icon + photoPixmap=SmallIcon(d->metaContact->statusIcon(), d->photoSize); + } + d->metaContactPhoto->setPixmap( photoPixmap, false); +} + +void MetaContactSelectorWidgetLVI::buildVisualComponents() +{ + // empty... + while ( component( 0 ) ) + delete component( 0 ); + + d->nameText = 0L; + d->metaContactPhoto = 0L; + d->extraText = 0L; + d->contactIconSize = 16; + d->photoSize = 48; + + Component *hbox = new BoxComponent( this, BoxComponent::Horizontal ); + d->spacerBox = new BoxComponent( hbox, BoxComponent::Horizontal ); + + d->contactIconSize = IconSize( KIcon::Small ); + Component *imageBox = new BoxComponent( hbox, BoxComponent::Vertical ); + new VSpacerComponent( imageBox ); + // include borders in size + d->metaContactPhoto = new ImageComponent( imageBox, d->photoSize + 2 , d->photoSize + 2 ); + new VSpacerComponent( imageBox ); + Component *vbox = new BoxComponent( hbox, BoxComponent::Vertical ); + d->nameText = new DisplayNameComponent( vbox ); + d->extraText = new TextComponent( vbox ); + + Component *box = new BoxComponent( vbox, BoxComponent::Horizontal ); + d->contactIconBox = new BoxComponent( box, BoxComponent::Horizontal ); + + slotUpdateContactBox(); + slotDisplayNameChanged(); + slotPhotoChanged(); +} + +void MetaContactSelectorWidgetLVI::slotUpdateContactBox() +{ + QPtrList<Kopete::Contact> contacts = d->metaContact->contacts(); + for(Kopete::Contact *c = contacts.first(); c; c = contacts.next()) + { + new ContactComponent(d->contactIconBox, c, IconSize( KIcon::Small )); + } +} + +class MetaContactSelectorWidget::Private +{ +public: + MetaContactSelectorWidget_Base *widget; + QValueList<Kopete::MetaContact *> excludedMetaContacts; +}; + + +MetaContactSelectorWidget::MetaContactSelectorWidget( QWidget *parent, const char *name ) + : QWidget( parent, name ), d( new Private() ) +{ + QBoxLayout *l = new QVBoxLayout(this); + d->widget = new MetaContactSelectorWidget_Base(this); + l->addWidget(d->widget); + + connect( d->widget->metaContactListView, SIGNAL( clicked(QListViewItem * ) ), + SIGNAL( metaContactListClicked( QListViewItem * ) ) ); + connect( d->widget->metaContactListView, SIGNAL( selectionChanged( QListViewItem * ) ), + SIGNAL( metaContactListClicked( QListViewItem * ) ) ); + connect( d->widget->metaContactListView, SIGNAL( spacePressed( QListViewItem * ) ), + SIGNAL( metaContactListClicked( QListViewItem * ) ) ); + + connect( Kopete::ContactList::self(), SIGNAL( metaContactAdded( Kopete::MetaContact * ) ), this, SLOT( slotLoadMetaContacts() ) ); + + d->widget->kListViewSearchLine->setListView(d->widget->metaContactListView); + d->widget->metaContactListView->setFullWidth( true ); + d->widget->metaContactListView->header()->hide(); + d->widget->metaContactListView->setColumnWidthMode(0, QListView::Maximum); + slotLoadMetaContacts(); +} + + +MetaContactSelectorWidget::~MetaContactSelectorWidget() +{ + disconnect( Kopete::ContactList::self(), SIGNAL( metaContactAdded( Kopete::MetaContact * ) ), this, SLOT( slotLoadMetaContacts() ) ); +} + + +Kopete::MetaContact* MetaContactSelectorWidget::metaContact() +{ + MetaContactSelectorWidgetLVI *item = 0L; + item = static_cast<MetaContactSelectorWidgetLVI *>( d->widget->metaContactListView->selectedItem() ); + + if ( item ) + return item->metaContact(); + + return 0L; +} + +void MetaContactSelectorWidget::selectMetaContact( Kopete::MetaContact *mc ) +{ + // iterate trough list view + QListViewItemIterator it( d->widget->metaContactListView ); + while( it.current() ) + { + MetaContactSelectorWidgetLVI *item = (MetaContactSelectorWidgetLVI *) it.current(); + if (!item) + continue; + + if ( mc == item->metaContact() ) + { + // select the contact item + d->widget->metaContactListView->setSelected( item, true ); + d->widget->metaContactListView->ensureItemVisible( item ); + } + ++it; + } +} + +void MetaContactSelectorWidget::excludeMetaContact( Kopete::MetaContact *mc ) +{ + if( d->excludedMetaContacts.findIndex(mc) == -1 ) + { + d->excludedMetaContacts.append(mc); + } + slotLoadMetaContacts(); +} + +bool MetaContactSelectorWidget::metaContactSelected() +{ + return d->widget->metaContactListView->selectedItem() ? true : false; +} + +/** Read in metacontacts from contactlist */ +void MetaContactSelectorWidget::slotLoadMetaContacts() +{ + d->widget->metaContactListView->clear(); + + QPtrList<Kopete::MetaContact> metaContacts = Kopete::ContactList::self()->metaContacts(); + for( Kopete::MetaContact *mc = metaContacts.first(); mc ; mc = metaContacts.next() ) + { + if( !mc->isTemporary() && (d->excludedMetaContacts.findIndex(mc) == -1) ) + { + new MetaContactSelectorWidgetLVI(mc, d->widget->metaContactListView); + } + } + + d->widget->metaContactListView->sort(); +} + +void MetaContactSelectorWidget::setLabelMessage( const QString &msg ) +{ + d->widget->lblHeader->setText(msg); +} + +} // namespace UI +} // namespace Kopete + +#include "metacontactselectorwidget.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/metacontactselectorwidget.h b/kopete/libkopete/ui/metacontactselectorwidget.h new file mode 100644 index 00000000..1c0a21ff --- /dev/null +++ b/kopete/libkopete/ui/metacontactselectorwidget.h @@ -0,0 +1,103 @@ +/* + MetaContactSelectorWidget + + Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org> + + Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef MetaContactSelectorWidget_H +#define MetaContactSelectorWidget_H + +#include <kdemacros.h> +#include <qwidget.h> +#include "kopetelistviewitem.h" +#include "kopete_export.h" + +class Kopete::MetaContact; + +namespace Kopete +{ +namespace UI +{ + +/** + * @author Duncan Mac-Vicar Prett <duncan@kde.org> + * This class provides a widget which allows easy selection + * of available Kopete metacontacts. + */ +class KOPETE_EXPORT MetaContactSelectorWidget : public QWidget +{ + Q_OBJECT +public: + MetaContactSelectorWidget( QWidget *parent = 0, const char *name = 0 ); + ~MetaContactSelectorWidget(); + Kopete::MetaContact* metaContact(); + /** + * sets the widget label message + * example: Please select a contact + * or, Choose a contact to delete + */ + void setLabelMessage( const QString &msg ); + /** + * pre-selects a contact + */ + void selectMetaContact( Kopete::MetaContact *mc ); + /** + * excludes a metacontact from being shown in the list + * if the metacontact is already excluded, do nothing + */ + void excludeMetaContact( Kopete::MetaContact *mc ); + /** + * @return true if there is a contact selected + */ + bool metaContactSelected(); +protected slots: + /** + * Utility function, populates the metacontact list + */ + void slotLoadMetaContacts(); +signals: + void metaContactListClicked( QListViewItem *mc ); +private: + class Private; + Private *d; +}; + +/** + * @author Duncan Mac-Vicar Prett <duncan@kde.org> + */ + +class MetaContactSelectorWidgetLVI : public Kopete::UI::ListView::Item +{ + Q_OBJECT +public: + MetaContactSelectorWidgetLVI(Kopete::MetaContact *mc, QListView *parent, QObject *owner = 0, const char *name = 0 ); + Kopete::MetaContact* metaContact(); + virtual QString text ( int column ) const; +protected slots: + void slotPhotoChanged(); + void slotDisplayNameChanged(); + void buildVisualComponents(); + void slotUpdateContactBox(); +private: + class Private; + Private *d; +}; + +} // namespace UI +} // namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/metacontactselectorwidget_base.ui b/kopete/libkopete/ui/metacontactselectorwidget_base.ui new file mode 100644 index 00000000..bc1a38eb --- /dev/null +++ b/kopete/libkopete/ui/metacontactselectorwidget_base.ui @@ -0,0 +1,107 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MetaContactSelectorWidget_Base</class> +<widget class="QWidget"> + <property name="name"> + <cstring>MetaContactSelectorWidget_Base</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>427</width> + <height>306</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>Select Contact</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KActiveLabel"> + <property name="name"> + <cstring>lblHeader</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>4</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lblSearch</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>S&earch:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kListViewSearchLine</cstring> + </property> + </widget> + <widget class="Kopete::UI::ListView::SearchLine"> + <property name="name"> + <cstring>kListViewSearchLine</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="Kopete::UI::ListView::ListView"> + <column> + <property name="text"> + <string>Meta Contact</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>metaContactListView</cstring> + </property> + </widget> + </vbox> +</widget> +<includes> + <include location="local" impldecl="in declaration">kopetelistviewsearchline.h</include> + <include location="local" impldecl="in declaration">kopetelistview.h</include> + <include location="global" impldecl="in declaration">qheader.h</include> +</includes> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +<includehints> + <includehint>kactivelabel.h</includehint> + <includehint>kopetelistviewsearchline.h</includehint> + <includehint>kopetelistview.h</includehint> +</includehints> +</UI> diff --git a/kopete/libkopete/ui/userinfodialog.cpp b/kopete/libkopete/ui/userinfodialog.cpp new file mode 100644 index 00000000..a25454a9 --- /dev/null +++ b/kopete/libkopete/ui/userinfodialog.cpp @@ -0,0 +1,277 @@ +/* + userinfodialog.h + + Copyright (c) 2003 by Zack Rusin <zack@kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "userinfodialog.h" +#include "kopeteuiglobal.h" + +#include <khtml_part.h> +#include <ktextbrowser.h> +#include <kapplication.h> +#include <klineedit.h> +#include <klocale.h> +#include <kdebug.h> + +#include <qlabel.h> +#include <qvbox.h> +#include <qlayout.h> + +namespace Kopete { + +struct UserInfoDialog::UserInfoDialogPrivate { + QString name; + QString id; + QString awayMessage; + QString status; + QString warningLevel; + QString onlineSince; + QString info; + QString address; + QString phone; + QMap<QString,QString> customFields; + QVBoxLayout *topLayout; + QWidget *page; + DialogStyle style; + KHTMLPart *htmlPart; + + KLineEdit *nameEdit; + KLineEdit *idEdit; + KLineEdit *statusEdit; + KLineEdit *warningEdit; + KLineEdit *onlineEdit; + KLineEdit *addressEdit; + KLineEdit *phoneEdit; + KTextBrowser *awayBrowser; + KTextBrowser *infoBrowser; +}; + +UserInfoDialog::UserInfoDialog( const QString& descr ) +: KDialogBase( Kopete::UI::Global::mainWidget(), "userinfodialog", true, i18n( "User Info for %1" ).arg( descr ), KDialogBase::Ok ) +{ + d = new UserInfoDialogPrivate; + d->page = new QWidget( this ); + setMainWidget( d->page ); + d->topLayout = new QVBoxLayout( d->page, 0, spacingHint() ); + d->style = Widget; +} + +UserInfoDialog::~UserInfoDialog() +{ + delete d; d=0; +} + +void UserInfoDialog::setStyle( DialogStyle style ) +{ + d->style = style; +} + +void UserInfoDialog::setName( const QString& name ) +{ + d->name = name; +} + +void UserInfoDialog::setId( const QString& id ) +{ + d->id = id; +} + +void UserInfoDialog::setAwayMessage( const QString& msg ) +{ + d->awayMessage = msg; +} + +void UserInfoDialog::setStatus( const QString& status ) +{ + d->status = status; +} + +void UserInfoDialog::setWarningLevel(const QString& level ) +{ + d->warningLevel = level; +} + +void UserInfoDialog::setOnlineSince( const QString& since ) +{ + d->onlineSince = since; +} + +void UserInfoDialog::setInfo( const QString& info ) +{ + d->info = info; +} + +void UserInfoDialog::setAddress( const QString& addr ) +{ + d->address = addr; +} + +void UserInfoDialog::setPhone( const QString& phone ) +{ + d->phone = phone; +} + +void UserInfoDialog::addCustomField( const QString& /*name*/, const QString& /*txt*/ ) +{ + +} + +void UserInfoDialog::addHTMLText( const QString& /*str*/ ) +{ + +} + +QHBox* UserInfoDialog::addLabelEdit( const QString& label, const QString& text, KLineEdit*& edit ) +{ + QHBox *box = new QHBox( d->page ); + new QLabel( label, box ); + edit = new KLineEdit( box ); + edit->setAlignment( Qt::AlignHCenter ); + edit->setText( text ); + edit->setReadOnly( true ); + return box; +} + +void UserInfoDialog::fillHTML() +{ + d->htmlPart = new KHTMLPart( this ); + + QString text; + /* + if ( d->name.isEmpty() ) { + text.append( QString("<div id=\"name\"><b>") + i18n("Name : ") + + QString("</b>") ); + text.append( d->name + QString("</div><br>") ); + } + + if ( d->id.isEmpty() ) { + text.append( "<div id=\"id\"><b>" + i18n("Id : ") + "</b>" ); + text.append( d->id + "</div><br>" ); + } + + if ( d->warningLevel.isEmpty() ) { + text.append( "<div id=\"warningLevel\"><b>" + i18n("Warning Level : ") + "</b>" ); + text.append( d->warningLevel + "</div><br>" ); + } + + if ( d->onlineSince.isEmpty() ) { + text.append( "<div id=\"onlineSince\"><b>" + i18n("Online Since : ") + "</b>" ); + text.append( d->onlineSince + "</div><br>" ); + } + + if ( d->address.isEmpty() ) { + text.append( "<div id=\"address\"><b>" + i18n("Address : ") + "</b>" ); + text.append( d->address + "</div><br>" ); + } + + if ( d->phone.isEmpty() ) { + text.append( "<div id=\"phone\"><b>" + i18n("Phone : ") + "</b>" ); + text.append( d->phone + "</div><br>" ); + } + + if ( d->status.isEmpty() ) { + text.append( "<div id=\"status\"><b>" + i18n("Status : ") + "</b>" ); + text.append( d->status + "</div><br>" ); + } + + if ( d->awayMessage.isEmpty() ) { + text.append( "<div id=\"awayMessage\"><b>" + i18n("Away Message : ") + "</b>" ); + text.append( d->awayMessage + "</div><br>" ); + } + + if ( d->info.isEmpty() ) { + text.append( "<div id=\"info\"><b>" + i18n("Info : ") + "</b>" ); + text.append( d->info + "</div><br>" ); + } +*/ + d->htmlPart->setOnlyLocalReferences( true ); + d->htmlPart->begin(); + d->htmlPart->write( text ); + d->htmlPart->end(); +} + +void UserInfoDialog::fillWidgets() +{ + kdDebug(14010)<<"Creating widgets"<<endl; + if ( !d->name.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Name:"), d->name, d->nameEdit ) ); + } + + if ( !d->id.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Contact ID:"), d->id, d->idEdit ) ); + } + + if ( !d->status.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Status:"), d->status, d->statusEdit ) ); + } + + if ( !d->warningLevel.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Warning level:"), d->warningLevel, d->warningEdit ) ); + } + + if ( !d->onlineSince.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Online since:"), d->onlineSince, d->onlineEdit ) ); + } + + if ( !d->address.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Address:"), d->address, d->addressEdit ) ); + } + + if ( !d->phone.isEmpty() ) { + d->topLayout->addWidget( addLabelEdit( i18n("Phone:"), d->phone, d->phoneEdit ) ); + } + + if ( !d->awayMessage.isEmpty() ) { + QVBox *awayBox = new QVBox( d->page ); + new QLabel( i18n("Away message:"), awayBox ); + d->awayBrowser = new KTextBrowser( awayBox ); + d->awayBrowser->setText( d->awayMessage ); + d->topLayout->addWidget( awayBox ); + } + + if ( !d->info.isEmpty() ) { + QVBox *infoBox = new QVBox( d->page ); + new QLabel( i18n("User info:"), infoBox ); + d->infoBrowser = new KTextBrowser( infoBox ); + d->infoBrowser->setText( d->info ); + d->topLayout->addWidget( infoBox ); + } +} + +void UserInfoDialog::setStyleSheet( const QString& /*css*/ ) +{ +} + +void UserInfoDialog::create() +{ + if ( d->style == HTML ) { + fillHTML(); + } else { + fillWidgets(); + } +} + +void UserInfoDialog::show() +{ + create(); + KDialogBase::show(); +} + +} + +#include "userinfodialog.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/userinfodialog.h b/kopete/libkopete/ui/userinfodialog.h new file mode 100644 index 00000000..7df19f4f --- /dev/null +++ b/kopete/libkopete/ui/userinfodialog.h @@ -0,0 +1,91 @@ +/* + userinfodialog.h + + Copyright (c) 2003 by Zack Rusin <zack@kde.org> + + Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef USERINFODIALOG_H +#define USERINFODIALOG_H + +#include <kdialogbase.h> +#include <qstring.h> + +#include "kopete_export.h" + +class KLineEdit; + +namespace Kopete { + + class KOPETE_EXPORT UserInfoDialog : public KDialogBase + { + Q_OBJECT + public: + UserInfoDialog( const QString& descr ); + virtual ~UserInfoDialog(); + + + /** + * Specifies the look of this dialog. If set to HTML only + * KHTMLPart will be in the dialog and it's look can be customized + * through setStyleSheet + * @see setStyleSheet + */ + enum DialogStyle { HTML, Widget }; + void setStyle( DialogStyle style ); + + // The functions below set elements as specified in the name. + // If an element is not set it won't be displayed. + void setName( const QString& name ); + void setId( const QString& id ); + void setAwayMessage( const QString& msg ); + void setStatus( const QString& status ); + void setWarningLevel(const QString& level ); + void setOnlineSince( const QString& since ); + void setInfo( const QString& info ); + void setAddress( const QString& addr ); + void setPhone( const QString& phone ); + + void addCustomField( const QString& name, const QString& txt ); + void addHTMLText( const QString& str ); + + ///Shows the dialog + virtual void show(); + protected: + /** + * This function has to be called after setting all the fields. + * It builds the GUI for the dialog. By default show() calls it. + */ + virtual void create(); + //Fills the dialog HTML if DialogStyle is HTML + virtual void fillHTML(); + //Fills the dialog with widgets if DialogStyle is Widget + virtual void fillWidgets(); + + /** + * If the DialogStyle is set to HTML one can customize the look of this + * dialog by setting the right stylesheet. The CSS id elements that can be + * customized include : "name", "id", "warningLevel", "onlineSince", + * "address", "phone", "status", "awayMessage" and "info". + */ + void setStyleSheet( const QString& css ); + + QHBox* addLabelEdit( const QString& label, const QString& text, KLineEdit*& edit ); + + private: + struct UserInfoDialogPrivate; + UserInfoDialogPrivate *d; + }; + +} +#endif diff --git a/kopete/libkopete/ui/widgets.cw b/kopete/libkopete/ui/widgets.cw new file mode 100644 index 00000000..7f3b38dc --- /dev/null +++ b/kopete/libkopete/ui/widgets.cw @@ -0,0 +1,21 @@ +<!DOCTYPE CW><CW> +<customwidgets> + <customwidget> + <class>Kopete::UI::PasswordWidget</class> + <header location="local">kopetepasswordwidget.h</header> + <sizehint> + <width>50</width> + <height>50</height> + </sizehint> + <container>0</container> + <sizepolicy> + <hordata>1</hordata> + <verdata>0</verdata> + </sizepolicy> + <pixmap> + <data format="XPM.GZ" length="4462">789c9d97c76e24490e86effd1442f3d65870d2451a0ce6206f5adeb4cc620f8c34f2553225b5a4c1befb46927fe6a1d4c0ccac4287fa8a0c26834193f5dbb785b3fd9d856fbf7d799ec9ecba5ea8afe469e15bf3727ffffeeffffcf1e797af49b2d0ffc7d142f2f55f5fbe1ecc16ea85dde9a4ed81290045faa77ca49cf4ab67ba1e3953969173651ab9d4fdf1c8a27c3872ad7c3c72d3b32c2a67c3f3444636fbef23eb7e590267e68fcc4656395d8dacf6d938ef97eaef289781cddebdb2846fccff44b989ba58e3411f3dc75158e6df1d3889539517ca49bf54fe43398d1dec4f46567f685fd9c539f43fc025f80c1c3ce8d93f28e77185f8bf0c6cfae4c0b5f9c3c6e5c0542a4b5876fe13708df39d2bd7716372aa8c93c4e4723bb2f977aadc26ceec4bdb7310e6b0bfab9c2445ecd49f1370694cebca65d260ffa6711a41aef14d24e94cee6be3348e0ae5e9c8765f07ca3e8db17f0f9c825794eb3489351fe9bb7217e4969f29388bd51ee9fda5715a19730696b852fea95c6471647ca95cf64bcf43e0cef4657b647bfe6acf213d6bb32f9a9f5992b5a64f9a8f990b6cf9ecc15d6cf9acf6b2da55a8a75cb973dee4b2d1b38b5c05de02434e87e01aacfb351df5bebddea74b5c67f9c795711ea15e357e2ecde358fb87efc0a867df8cac728a074e62e527706afb59f3cf6583be5c28bb3c35f693812d1fbdc6dbe57966fec932d899ffa4f7e38adca17e34beaeca4b9c271a18f1d5fc739257b0d70d9c68be7bed7fcee7827ab91cd8e4740cf6b19d4ffb87ab07b9bf516e72d4a3ac821b9cef6e60d84f47367ded2fae1d9f7704f6163f79000ffde27660f387ed3c5dbf54dfeebb0bf6acbe6b706bfa5ef32f8f8b18f5bf0f463f20edb77956a4e68fbc80b3c4facd163847be6bfde72ec86dbeac82715fbc0286be683cf3bc081d44f7df80d344fb0b6b7de64581fb916765297263d6fccd9b7ee97e566e8b06cfdb1f59cf2bda2f8bbc2c11df0c5c41aefdb328ca22b1feb0012eedbce24736f91b18fb796d64eb87cb60817dcdafb07d906bfd14d22f659d8785ef97b2f6d7b2df6ef1d6fb2babaac6f92e8c25b27ecc1f239b7f3a5fca5a8678ea7c2d9bc0e6ef1238b3fca2c7814d5f4cbf9334b5f833384bed3c7a5f5514f4adbe2ec07962e7590457f06f6f649b977afe2a16f42f5e070bfc591e18f7a5f1a812a9e0df39d827da4fbd8c6ccfd7785569bf945f953371a9d5a3de67950bfa2d75c63eb2fb15bdcfaaf011e6c7263846bf8f4636f91618f3c7d3c0f047fb69550efab2074e12bd6fd27957553ec33c5b043bcc7f9d0795f818fdb501a3df8ae673e507ff69021eea37063bc45ffb73550736ff36c0a84f3e0317a86f8b5f139e6ffe1f821de6d9127898ff3be00a7c3ab2cd03e3d697560ff40016e47b3bb2e96bbd559d8f32bbff4b7065f193042c98873acf240af6adbf3c83c5f2954bb0c7bcd77c107d81d2fdebc63e33ff640aaecc9e1c8151df5c803dfaadc64b52dfa03ed64636ffb4ff4b2867f453ede7227586fcd3f9264ded91fffafe236d5da37fe83c91ceb7b9e5b7f6731ff92ed7f747d6fbf7e185cf58347e3e6932e47b3430fa893edf87d795c2fc3f003b67f5f902cec17abfde0dfa3c053b3c5ffb832fc2eb8fddcf233887fc195c801f46b6f3cdc02558fba72f7d2d1a7f7e321ee58fe0cad86bbff24dd3e2fe74fef836b0c6eb60d62fa6bf5e07b3419f853dd7dc70fb8bd5f1255fd90ed30f9f3c5ff30ddff21ddff384a7fcc08ffcc4cf61cdf8855ff9e79c7e1db4dff89d3f7891977899577895d7789d377893b7f83b6fcfe937bc13b477798ff7f9800ff928ac633ee11f7cca6761d7f99c7e1b3cb908da11c7413be1943376e153cc39175c72f549ff9e17c31744429e6a6aa8a58e2ee98aaee9866e7f617fc24b7417a4f734a1293dd0233dd133cd8285177aa5f9f3b63ca5377aa78f607b919668995682e62aadd17ab0b1419b9ff41f682b48bed336edd02eed05ed7d5ea3033a0cdf1ed1f127fd273ae123fa41a774a6b685cee982228a837e42e927fd47caf8985c38651eb40b2ac38e4a5842658a97fab33fd248cb87d2c9a55cc9b5dcc82d1fc99ddccb44a6f230af2f8ff224cf417f262ff22a3fe54ddee543166549966545567f617f4dd66523dc6b2c9bb225df655b7682f692ecca9eeccfe97772c09b722847722c27c1f3eb70f66bf9116c9fca999ccbc59cfe25bf4a143a5ef8992561324a78bd92522acf9ebc78efe7cf7b153276db37bef59dbff457fedadff85b7f27abfede4ffcd4cf9ff76faeff4fffefeff8c7f5fedfdfbffc0fa355c495</data> + </pixmap> + <signal>changed()</signal> + </customwidget> +</customwidgets> +</CW> |