1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 04:21:51 +02:00

Make the treeview work, and config work, and lots of things work

This commit is contained in:
Leo Franchi 2011-04-29 16:05:48 -04:00
parent e2f0bc6c17
commit bba33f0bf8
32 changed files with 765 additions and 139 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 757 B

View File

@ -110,7 +110,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
resolverconfigdelegate.h
sipconfigdelegate.h
resolversmodel.h
resolverconfigwrapper.h
delegateconfigwrapper.h
tomahawkwindow.h
)

View File

@ -52,7 +52,7 @@ ConfigDelegateBase::sizeHint( const QStyleOptionViewItem& option, const QModelIn
QFontMetrics bfm( name );
QFontMetrics sfm( path );
return QSize( width, 3 * PADDING + bfm.height() + sfm.height() );
return QSize( width, 2 * PADDING + bfm.height() + sfm.height() );
}
void

View File

@ -22,14 +22,15 @@
#include <QDialogButtonBox>
#include <QVBoxLayout>
class ResolverConfigWrapper : public QDialog
class DelegateConfigWrapper : public QDialog
{
Q_OBJECT
public:
ResolverConfigWrapper( QWidget* conf, const QString& title, QWidget* parent ) : QDialog( parent ), m_widget( conf )
DelegateConfigWrapper( QWidget* conf, const QString& title, QWidget* parent ) : QDialog( parent ), m_widget( conf )
{
setWindowTitle( title );
m_widget->setVisible( true );
setWindowTitle( title );
QVBoxLayout* v = new QVBoxLayout( this );
v->addWidget( m_widget );
@ -46,6 +47,7 @@ public slots:
// let the config widget live to see another day
layout()->removeWidget( m_widget );
m_widget->setParent( 0 );
m_widget->setVisible( false );
QDialogButtonBox* buttons = qobject_cast< QDialogButtonBox* >( sender() );
if( buttons->standardButton( b ) == QDialogButtonBox::Ok )
@ -59,6 +61,7 @@ public slots:
{
layout()->removeWidget( m_widget );
m_widget->setParent( 0 );
m_widget->setVisible( false );
}
private:

View File

@ -243,6 +243,21 @@ SipHandler::checkSettings()
}
}
void
SipHandler::addSipPlugin( SipPlugin* p, bool enabled, bool startup )
{
m_allPlugins << p;
if ( enabled )
{
p->connectPlugin( startup );
m_enabledPlugins << p;
}
emit pluginAdded( p );
}
void
SipHandler::loadFromConfig( bool startup )
{
@ -254,13 +269,7 @@ SipHandler::loadFromConfig( bool startup )
if( m_pluginFactories.contains( pluginFactory ) )
{
SipPlugin* p = loadPlugin( pluginId );
m_allPlugins << p;
if ( enabled.contains( pluginId ) )
{
p->connectPlugin( startup );
m_enabledPlugins << p;
}
addSipPlugin( p, enabled.contains( pluginId ), startup );
}
}
m_connected = true;

View File

@ -44,6 +44,8 @@ public:
QList< SipPlugin* > connectedPlugins() const;
void loadFromConfig( bool startup = false );
void addSipPlugin( SipPlugin* p, bool enable = true, bool connectImmediately = true );
const QPixmap avatar( const QString& name ) const;
public slots:

View File

@ -21,11 +21,20 @@
#include "tomahawksettings.h"
#include "tomahawk/tomahawkapp.h"
#include "sip/SipHandler.h"
#include "sip/SipPlugin.h"
SipModel::SipModel( QObject* parent )
: QAbstractItemModel( parent )
{
connect( SipHandler::instance(), SIGNAL( stateChanged( SipPlugin*, SipPlugin::ConnectionState ) ), this, SLOT( pluginStateChanged( SipPlugin* ) ) );
connect( SipHandler::instance(), SIGNAL( pluginAdded( SipPlugin* ) ), this, SLOT( pluginAdded( SipPlugin* ) ) );
connect( SipHandler::instance(), SIGNAL( pluginRemoved( SipPlugin* ) ), this, SLOT( pluginRemoved( SipPlugin* ) ) );
foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) {
if( f->isCreatable() )
m_factories << f;
}
}
@ -40,36 +49,59 @@ SipModel::data( const QModelIndex& index, int role ) const
if( !index.isValid() )
return QVariant();
if( index.row() == SipHandler::instance()->allPlugins().count() ) { // last row, this is the factory
if( !index.parent().isValid() && index.row() == SipHandler::instance()->allPlugins().count() ) { // last row, this is the factory
if( role == Qt::DisplayRole )
return tr( "Add New Account" );
return tr( "Add New Account..." );
else if( role == FactoryRole )
return true;
else
return QVariant();
}
QList< SipPlugin* > plugins = SipHandler::instance()->allPlugins();
Q_ASSERT( index.row() <= plugins.size() );
SipPlugin* p = plugins[ index.row() ];
switch( role )
{
if( !index.parent().isValid() ) { // account
QList< SipPlugin* > plugins = SipHandler::instance()->allPlugins();
Q_ASSERT( index.row() <= plugins.size() );
SipPlugin* p = plugins[ index.row() ];
switch( role )
{
case Qt::DisplayRole:
case SipModel::PluginName:
return p->accountName();
case SipModel::ConnectionStateRole:
return p->connectionState();
case SipModel::HasConfig:
return ( p->configWidget() != 0 );
case SipModel::FactoryRole:
return false;
case Qt::DecorationRole:
return p->icon();
case SipModel::SipPluginData:
return QVariant::fromValue< QObject* >( p );
case Qt::CheckStateRole:
return SipHandler::instance()->enabledPlugins().contains( p ) ? Qt::Checked : Qt::Unchecked;
default:
return QVariant();
}
}
if( index.parent().isValid() ) { // this is a factory type
SipPluginFactory* p = m_factories.at( index.row() );
switch( role )
{
case Qt::DisplayRole:
case SipModel::PluginName:
return p->accountName();
case SipModel::ConnectionStateRole:
return p->connectionState();
case SipModel::HasConfig:
return ( p->configWidget() == 0 );
case SipModel::FactoryRole:
return false;
case Qt::DecorationRole:
return p->prettyName();
case SipModel::FactoryItemRole:
return true;
case SipModel::FactoryItemIcon:
return p->icon();
case Qt::CheckStateRole:
return SipHandler::instance()->enabledPlugins().contains( p ) ? Qt::Checked : Qt::Unchecked;
case SipModel::SipPluginFactoryData:
return QVariant::fromValue< QObject* >( p );
default:
return QVariant();
}
}
return QVariant();
}
bool
@ -100,9 +132,10 @@ SipModel::index( int row, int column, const QModelIndex& parent ) const
if( !parent.isValid() )
return hasIndex( row, column, parent ) ? createIndex( row, column, 0 ) : QModelIndex();
// qDebug() << "Creating index for non-top level row!";
// it's a child of the Add Account, e.g. a factory
if( hasIndex( row, column, parent ) ) {
createIndex( row, column, 1 /* magic */ );
return createIndex( row, column, 1 /* magic */ );
}
return QModelIndex();
@ -115,7 +148,7 @@ SipModel::parent( const QModelIndex& child ) const
return QModelIndex();
if( child.internalId() == 1 ) {
return createIndex( SipHandler::instance()->allPlugins().size() - 1, 0, 0 );
return index( SipHandler::instance()->allPlugins().size(), 0, QModelIndex() );
}
return QModelIndex();
@ -124,25 +157,29 @@ SipModel::parent( const QModelIndex& child ) const
int
SipModel::rowCount( const QModelIndex& parent ) const
{
if( !parent.isValid() ) { // top level item
if( parent.row() == SipHandler::instance()->allPlugins().count() ) { // last row, this is the factory
return SipHandler::instance()->pluginFactories().count();
} else {
return SipHandler::instance()->allPlugins().size() + 1;
if( !parent.isValid() ) // invalid root node
return SipHandler::instance()->allPlugins().size() + 1;
if( parent.isValid() && !parent.parent().isValid() ) { // top level item
if( parent.row() == SipHandler::instance()->allPlugins().count() ) {// last row, this is the factory
return m_factories.count();
}
}
return 0;
}
int
SipModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED( parent );
return 1;
}
Qt::ItemFlags
SipModel::flags( const QModelIndex& index ) const
{
if( index.data( SipModel::FactoryRole ).toBool() || index.data( SipModel::FactoryItemRole ).toBool() )
return QAbstractItemModel::flags( index ) & ~Qt::ItemIsSelectable;
return QAbstractItemModel::flags( index ) | Qt::ItemIsUserCheckable;
}
@ -153,6 +190,7 @@ SipModel::pluginAdded( SipPlugin* p )
Q_ASSERT( SipHandler::instance()->allPlugins().last() == p );
int size = SipHandler::instance()->allPlugins().count() - 1;
beginInsertRows( QModelIndex(), size, size );
endInsertRows();
}
void

View File

@ -25,6 +25,7 @@
#include <QModelIndex>
#include <QStringList>
class SipPluginFactory;
class SipPlugin;
class DLLEXPORT SipModel : public QAbstractItemModel
@ -36,7 +37,11 @@ public:
ConnectionStateRole = Qt::UserRole + 17,
HasConfig = Qt::UserRole + 18,
FactoryRole = Qt::UserRole + 19,
ErrorString = Qt::UserRole + 20
ErrorString = Qt::UserRole + 20,
FactoryItemRole = Qt::UserRole + 21,
FactoryItemIcon = Qt::UserRole + 22,
SipPluginData = Qt::UserRole + 23,
SipPluginFactoryData = Qt::UserRole + 24
};
explicit SipModel( QObject* parent = 0 );
@ -54,6 +59,9 @@ private slots:
void pluginAdded( SipPlugin* p );
void pluginRemoved( SipPlugin* p );
void pluginStateChanged( SipPlugin* p );
private:
QList< SipPluginFactory* > m_factories;
};
#endif // SIPMODEL_H

View File

@ -38,6 +38,9 @@ public:
virtual QString prettyName() const = 0;
// internal name
virtual QString factoryId() const = 0;
// if the user can create multiple
virtual QIcon icon() const { return QIcon(); }
virtual bool isCreatable() const { return true; }
virtual SipPlugin* createPlugin( const QString& pluginId = QString() ) = 0;
protected:
@ -66,6 +69,7 @@ public:
virtual QString errorMessage() const;
virtual QMenu* menu();
virtual QWidget* configWidget();
virtual void saveConfig() {} // called when the widget has been edited
virtual QIcon icon() const;
public slots:

View File

@ -42,7 +42,7 @@
#include "scanmanager.h"
#include "resolverconfigdelegate.h"
#include "resolversmodel.h"
#include "resolverconfigwrapper.h"
#include "delegateconfigwrapper.h"
#include "sip/SipModel.h"
#include "sipconfigdelegate.h"
@ -73,16 +73,11 @@ SettingsDialog::SettingsDialog( QWidget *parent )
// SIP PLUGINS
SipConfigDelegate* sipdel = new SipConfigDelegate( this );
ui->accountsView->setItemDelegate( sipdel );
// connect( sipdel, SIGNAL( openConfig( SipPlugin* ) ), this, SLOT( openSipPluginConfig( SipPlugin* ) ) );
connect( ui->accountsView, SIGNAL( clicked( QModelIndex ) ), this, SLOT( sipItemClicked( QModelIndex ) ) );
connect( sipdel, SIGNAL( openConfig( SipPlugin* ) ), this, SLOT( openSipConfig( SipPlugin* ) ) );
m_sipModel = new SipModel( this );
ui->accountsView->setModel( m_sipModel );
// ui->checkBoxJabberAutoConnect->setChecked( s->jabberAutoConnect() );
// ui->jabberUsername->setText( s->jabberUsername() );
// ui->jabberPassword->setText( s->jabberPassword() );
// ui->jabberServer->setText( s->jabberServer() );
// ui->jabberPort->setValue( s->jabberPort() );
ui->staticHostName->setText( s->externalHostname() );
ui->staticPort->setValue( s->externalPort() );
@ -368,8 +363,8 @@ SettingsDialog::openResolverConfig( const QString& resolver )
{
Tomahawk::ExternalResolver* r = TomahawkApp::instance()->resolverForPath( resolver );
if( r && r->configUI() ) {
ResolverConfigWrapper dialog( r->configUI(), "Resolver Config", this );
QWeakPointer< ResolverConfigWrapper > watcher( &dialog );
DelegateConfigWrapper dialog( r->configUI(), "Resolver Config", this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) {
// send changed config to resolver
@ -377,3 +372,56 @@ SettingsDialog::openResolverConfig( const QString& resolver )
}
}
}
void
SettingsDialog::sipItemClicked( const QModelIndex& item )
{
if( item.data( SipModel::FactoryRole ).toBool() )
if( ui->accountsView->isExpanded( item ) )
ui->accountsView->collapse( item );
else
ui->accountsView->expand( item );
else if( item.data( SipModel::FactoryItemRole ).toBool() )
sipFactoryClicked( qobject_cast<SipPluginFactory* >( item.data( SipModel::SipPluginFactoryData ).value< QObject* >() ) );
}
void
SettingsDialog::openSipConfig( SipPlugin* p )
{
if( p->configWidget() ) {
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) {
// send changed config to resolver
p->saveConfig();
}
}
}
void
SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
{
Q_ASSERT( factory->isCreatable() );
//if exited with OK, create it, if not, delete it immediately!
SipPlugin* p = factory->createPlugin();
if( p->configWidget() ) {
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) {
// send changed config to resolver
p->saveConfig();
// accepted, so add it to tomahawk
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
SipHandler::instance()->addSipPlugin( p );
} else {
// canceled, delete it
delete p;
}
} else {
// no config, so just add it
SipHandler::instance()->addSipPlugin( p );
}
}

View File

@ -20,7 +20,10 @@
#define SETTINGSDIALOG_H
#include <QDialog>
#include <QModelIndex>
class SipPluginFactory;
class SipPlugin;
class SipModel;
class ResolversModel;
class QNetworkReply;
@ -74,6 +77,9 @@ private slots:
void scriptSelectionChanged();
void removeScriptResolver();
void openResolverConfig( const QString& );
void sipItemClicked ( const QModelIndex& );
void openSipConfig( SipPlugin* );
void sipFactoryClicked( SipPluginFactory* );
private:
Ui::SettingsDialog* ui;

View File

@ -32,6 +32,9 @@
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<widget class="QTreeView" name="accountsView">
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
@ -44,6 +47,9 @@
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
</layout>

View File

@ -22,13 +22,19 @@ set( jabberHeaders
avatarmanager.h
)
set( jabberUI
configwidget.ui
)
include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
${QT_INCLUDE_DIR}
${LIBJREEN_INCLUDE_DIR}
)
qt4_add_resources( RC_SRCS "resources.qrc" )
qt4_wrap_ui( jabberUI_H ${jabberUI} )
qt4_wrap_cpp( jabberMoc ${jabberHeaders} )
add_library( tomahawk_sipjabber SHARED ${jabberSources} ${jabberMoc} )
add_library( tomahawk_sipjabber SHARED ${jabberSources} ${jabberMoc} ${jabberUI_H} ${RC_SRCS} )
IF( WIN32 )
SET( OS_SPECIFIC_LINK_LIBRARIES
@ -53,4 +59,4 @@ ENDIF( APPLE )
install( TARGETS tomahawk_sipjabber DESTINATION lib${LIB_SUFFIX} )
add_subdirectory(googlewrapper)
add_subdirectory(googlewrapper)

View File

@ -0,0 +1,264 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JabberConfig</class>
<widget class="QWidget" name="JabberConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>207</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="headerLabel">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Configure this Jabber account</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Login Information</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="emailLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Jabber ID:</string>
</property>
<property name="buddy">
<cstring>jabberUsername</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="jabberUsername">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>e.g. user@example.com</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Password:</string>
</property>
<property name="buddy">
<cstring>jabberPassword</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="jabberPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMask">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAutoConnect">
<property name="text">
<string>Connect automatically when Tomahawk starts</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxJabberAdvanced">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Advanced Jabber Settings</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labelJabberServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Server:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>jabberServer</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="jabberServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelJabberPort">
<property name="text">
<string>Port:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="jabberPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>5222</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -18,8 +18,10 @@ set( googleSources
add_definitions(-DGOOGLE_WRAPPER)
qt4_add_resources( RCX_SRCS "resources.qrc" )
qt4_wrap_cpp( googleMoc googlewrapper.h )
add_library( tomahawk_sipgoogle SHARED ${googleSources} ${googleMoc} ${jabberMoc} )
add_library( tomahawk_sipgoogle SHARED ${googleSources} ${googleMoc} ${jabberMoc} ${RCX_SRCS} )
target_link_libraries( tomahawk_sipgoogle
${QT_LIBRARIES}

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View File

@ -20,18 +20,35 @@
#include "googlewrapper.h"
#include <QtPlugin>
#include "ui_configwidget.h"
SipPlugin*
GoogleWrapperFactory::createPlugin( const QString& pluginId )
{
return new GoogleWrapper( pluginId.isEmpty() ? generateId() : pluginId );
}
QIcon
GoogleWrapperFactory::icon() const
{
return QIcon( ":/gmail-logo.jpg" );
}
GoogleWrapper::GoogleWrapper ( const QString& pluginID )
: JabberPlugin ( pluginID )
{
m_ui->headerLabel->setText( tr( "Configure this Google Account" ) );
m_ui->emailLabel->setText( tr( "GMail Address" ) );
}
QIcon
GoogleWrapper::icon() const
{
return QIcon( ":/gmail-logo.jpg" );
}
#ifdef GOOGLE_WRAPPER
Q_EXPORT_PLUGIN2( sipfactory, GoogleWrapperFactory )
#endif

View File

@ -32,6 +32,7 @@ public:
virtual QString prettyName() const { return "GMail"; }
virtual QString factoryId() const { return "sipgoogle"; }
virtual QIcon icon() const;
virtual SipPlugin* createPlugin( const QString& pluginId );
};
@ -44,6 +45,7 @@ public:
virtual const QString name() const { return QString( "GMail" ); }
virtual const QString friendlyName() const { return "GMail Friends"; }
virtual QIcon icon() const;
};
#endif // GOOGLEWRAPPER_H

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>gmail-logo.jpg</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -27,12 +27,21 @@
#include <QLineEdit>
#include <QMessageBox>
#include "ui_configwidget.h"
SipPlugin*
JabberFactory::createPlugin( const QString& pluginId )
{
return new JabberPlugin( pluginId.isEmpty() ? generateId() : pluginId );
}
QIcon
JabberFactory::icon() const
{
return QIcon( ":/jabber-icon.png" );
}
JabberPlugin::JabberPlugin( const QString& pluginId )
: SipPlugin( pluginId )
, p( 0 )
@ -40,6 +49,17 @@ JabberPlugin::JabberPlugin( const QString& pluginId )
, m_addFriendAction( 0 )
, m_state( Disconnected )
{
m_configWidget = QWeakPointer< QWidget >( new QWidget );
m_ui = new Ui_JabberConfig;
m_ui->setupUi( m_configWidget.data() );
m_configWidget.data()->setVisible( false );
m_ui->checkBoxAutoConnect->setChecked( readAutoConnect() );
m_ui->jabberUsername->setText( accountName() );
m_ui->jabberPassword->setText( readPassword() );
m_ui->jabberServer->setText( readServer() );
m_ui->jabberPort->setValue( readPort() );
}
JabberPlugin::~JabberPlugin()
@ -78,6 +98,19 @@ JabberPlugin::menu()
return m_menu;
}
QWidget*
JabberPlugin::configWidget()
{
return m_configWidget.data();
}
QIcon
JabberPlugin::icon() const
{
return QIcon( ":/jabber-icon.png" );
}
bool
JabberPlugin::connectPlugin( bool startup )
{
@ -285,6 +318,19 @@ JabberPlugin::readAutoConnect()
return TomahawkSettings::instance()->value( pluginId() + "/autoconnect", true ).toBool();
}
void
JabberPlugin::saveConfig()
{
TomahawkSettings::instance()->setValue( pluginId() + "/autoconnect", m_ui->checkBoxAutoConnect->isChecked() );
TomahawkSettings::instance()->setValue( pluginId() + "/username", m_ui->jabberUsername->text() );
TomahawkSettings::instance()->setValue( pluginId() + "/pasword", m_ui->jabberPassword->text() );
TomahawkSettings::instance()->setValue( pluginId() + "/port", m_ui->jabberPort->value() );
TomahawkSettings::instance()->setValue( pluginId() + "/server", m_ui->jabberServer->text() );
checkSettings();
}
SipPlugin::ConnectionState
JabberPlugin::connectionState() const
{

View File

@ -27,6 +27,8 @@
#define MYNAME "SIPJREEN"
class Ui_JabberConfig;
class SIPDLLEXPORT JabberFactory : public SipPluginFactory
{
Q_OBJECT
@ -38,6 +40,7 @@ public:
virtual QString prettyName() const { return "Jabber"; }
virtual QString factoryId() const { return "sipjabber"; }
virtual QIcon icon() const;
virtual SipPlugin* createPlugin( const QString& pluginId );
};
@ -56,6 +59,9 @@ public:
virtual const QString accountName() const;
virtual ConnectionState connectionState() const;
virtual QMenu* menu();
virtual QIcon icon() const;
virtual QWidget* configWidget();
virtual void saveConfig();
void setProxy( QNetworkProxy* proxy );
@ -67,6 +73,9 @@ public slots:
void broadcastMsg( const QString &msg );
void addContact( const QString &jid, const QString& msg = QString() );
protected:
Ui_JabberConfig* m_ui; // so the google wrapper can change the config dialog a bit
private slots:
void showAddFriendDialog();
void onConnected();
@ -88,6 +97,8 @@ private:
QString m_currentServer;
unsigned int m_currentPort;
ConnectionState m_state;
QWeakPointer< QWidget > m_configWidget;
};
#endif

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>jabber-icon.png</file>
</qresource>
</RCC>

View File

@ -26,9 +26,10 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
${CMAKE_SOURCE_DIR}/thirdparty/qtweetlib/tomahawk-custom
)
qt4_add_resources( RC_SRCS "resources.qrc" )
qt4_wrap_cpp( twitterMoc ${twitterHeaders} )
qt4_wrap_ui( twitterUI_H ${twitterUI} )
add_library( tomahawk_siptwitter SHARED ${twitterUI_H} ${twitterSources} ${twitterMoc} )
add_library( tomahawk_siptwitter SHARED ${twitterUI_H} ${twitterSources} ${twitterMoc} ${RC_SRCS} )
IF( WIN32 )
SET( OS_SPECIFIC_LINK_LIBRARIES

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>twitter-icon.jpg</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -41,6 +41,11 @@ TwitterFactory::createPlugin( const QString& pluginId )
return new TwitterPlugin( pluginId.isEmpty() ? generateId() : pluginId );
}
QIcon TwitterFactory::icon() const
{
return QIcon( ":/twitter-icon.jpg" );
}
TwitterPlugin::TwitterPlugin( const QString& pluginId )
: SipPlugin( pluginId )
@ -55,7 +60,6 @@ TwitterPlugin::TwitterPlugin( const QString& pluginId )
, m_finishedFriends( false )
, m_finishedMentions( false )
, m_state( Disconnected )
, m_configWidget( 0 )
{
qDebug() << Q_FUNC_INFO;
m_checkTimer.setInterval( 60000 );
@ -65,18 +69,29 @@ TwitterPlugin::TwitterPlugin( const QString& pluginId )
m_connectTimer.setInterval( 60000 );
m_connectTimer.setSingleShot( false );
connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) );
m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );
connect( m_configWidget.data(), SIGNAL( twitterAuthed( bool ) ), SLOT( configDialogAuthedSignalSlot( bool ) ) );
}
void
TwitterPlugin::configDialogAuthedSignalSlot( bool authed )
{
m_isAuthed = authed;
if ( !authed )
{
if( m_isAuthed ) {
m_state = Disconnected;
emit stateChanged( m_state );
}
setTwitterScreenName( QString() );
setTwitterOAuthToken( QString() );
setTwitterOAuthTokenSecret( QString() );
}
m_isAuthed = authed;
}
bool
@ -100,9 +115,19 @@ TwitterPlugin::friendlyName() const
const QString
TwitterPlugin::accountName() const
{
return twitterScreenName();
if( twitterScreenName().isEmpty() )
return friendlyName();
else
return twitterScreenName();
}
QIcon
TwitterPlugin::icon() const
{
return QIcon( ":/twitter-icon.jpg" );
}
SipPlugin::ConnectionState
TwitterPlugin::connectionState() const
{
@ -112,11 +137,7 @@ TwitterPlugin::connectionState() const
QWidget* TwitterPlugin::configWidget()
{
m_configWidget = new TwitterConfigWidget( this, 0 );
connect( m_configWidget, SIGNAL( twitterAuthed(bool) ), SLOT( configDialogAuthedSignalSlot(bool) ) );
return m_configWidget;
return m_configWidget.data();
}
bool

View File

@ -51,6 +51,7 @@ public:
virtual QString prettyName() const { return "Twitter"; }
virtual QString factoryId() const { return "siptwitter"; }
virtual QIcon icon() const;
virtual SipPlugin* createPlugin( const QString& pluginId = QString() );
};
@ -68,6 +69,7 @@ public:
virtual const QString accountName() const;
virtual const QString friendlyName() const;
virtual ConnectionState connectionState() const;
virtual QIcon icon() const;
virtual QWidget* configWidget();
public slots:
@ -146,7 +148,7 @@ private:
bool m_finishedMentions;
ConnectionState m_state;
TwitterConfigWidget *m_configWidget;
QWeakPointer<TwitterConfigWidget > m_configWidget;
// for settings access
friend class TwitterConfigWidget;

View File

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>795</width>
<height>509</height>
<width>438</width>
<height>266</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<layout class="QVBoxLayout" name="twitterVertLayout">

View File

@ -36,6 +36,7 @@ public:
virtual QString factoryId() const { return "sipzeroconf"; }
virtual QString prettyName() const { return "Local Network"; }
virtual bool isCreatable() const { return false; };
virtual SipPlugin* createPlugin ( const QString& pluginId = QString() );
};

View File

@ -27,7 +27,7 @@
SipConfigDelegate::SipConfigDelegate( QObject* parent )
: ConfigDelegateBase ( parent )
{
connect( this, SIGNAL( configPressed( QModelIndex ) ), this, SLOT( askedForEdit( QModelIndex ) ) );
}
bool
@ -44,7 +44,6 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
QRect itemRect = opt.rect;
int top = itemRect.top();
int mid = itemRect.height() / 2;
int leftEdge = PADDING;
// one line bold for account name
// space below it fro an error
@ -62,83 +61,182 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
QStyle* style = w ? w->style() : QApplication::style();
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
// draw checkbox first
int rectW = 24;
int pos = ( mid ) - ( rectW / 2 );
QRect checkRect = QRect( pos, pos + top, rectW, rectW );
opt.rect = checkRect;
drawCheckBox( opt, painter, w );
// draw the icon if it exists
leftEdge = checkRect.right() + PADDING;
int iconSize = 24;
pos = ( mid ) - ( iconSize / 2 );
if( !index.data( Qt::DecorationRole ).value< QIcon >().isNull() ) {
QRect prect = QRect( leftEdge, pos + top, iconSize, iconSize );
int checkLeftEdge = 8;
int iconLeftEdge = checkLeftEdge + iconSize + PADDING;
int textLeftEdge = iconLeftEdge + iconSize + PADDING;
if( index.data( SipModel::FactoryRole ).toBool() ) { // this is the "add new account" row
// draw a border and background
painter->save();
painter->drawPixmap( prect, index.data( Qt::DecorationRole ).value< QIcon >().pixmap( prect.size() ) );
painter->setRenderHints( QPainter::Antialiasing );
painter->setBrush( QApplication::palette().color( QPalette::Active, QPalette::Highlight ).lighter( 150 ) );
QPainterPath roundedRect;
roundedRect.addRoundedRect( itemRect.adjusted( 1, 1, -1, -1 ), 3, 3 );
painter->drawPath( roundedRect );
painter->setBrush( QApplication::palette().color( QPalette::Active, QPalette::Highlight ).lighter( 170 ) );
painter->fillPath( roundedRect, painter->brush() );
painter->restore();
// draw "+" icon in checkbox column
int rectW = 18;
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
int pos = ( mid ) - ( rectW / 2 );
QRect plusRect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
QPixmap p( RESPATH "images/list-add.png" );
painter->drawPixmap( plusRect, p );
// draw text
QFont f = opt.font;
f.setPointSize( f.pointSize() );
f.setBold( true );
QFontMetrics fm( f );
QString text = index.data( Qt::DisplayRole ).toString();
QRect textR = fm.boundingRect( text );
textR.moveLeft( textLeftEdge );
textR.moveTop( mid - ( textR.height() / 2 ) + top );
textR.setRight( itemRect.right() );
painter->setFont( f );
painter->drawText( textR, text );
} else if( index.data( SipModel::FactoryItemRole ).toBool() ) { // this is an account type
// ConfigDelegateBase::paint( painter, opt, index );
// int indent = 10;
// draw a border and background
painter->save();
painter->setRenderHints( QPainter::Antialiasing );
painter->setBrush( QApplication::palette().color( QPalette::Active, QPalette::Highlight ).lighter( 170 ) );
QPainterPath roundedRect;
roundedRect.addRoundedRect( itemRect.adjusted( 1, 1, -1, -1 ), 3, 3 );
painter->drawPath( roundedRect );
painter->setBrush( QApplication::palette().color( QPalette::Active, QPalette::Highlight ).lighter( 180 ) );
painter->fillPath( roundedRect, painter->brush() );
painter->restore();
QIcon icon = index.data( SipModel::FactoryItemIcon ).value< QIcon >();
if( !icon.isNull() ) {
int rectW = 18;
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
int pos = ( mid ) - ( rectW / 2 );
QRect rect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
QPixmap p( icon.pixmap( rect.size() ) );
painter->drawPixmap( rect, p );
}
// draw text
QFont f = opt.font;
f.setPointSize( f.pointSize() );
f.setBold( true );
QFontMetrics fm( f );
QString text = index.data( Qt::DisplayRole ).toString();
QRect textR = fm.boundingRect( text );
textR.moveLeft( textLeftEdge );
textR.moveTop( mid - ( textR.height() / 2 ) + top );
textR.setRight( itemRect.right() );
painter->setFont( f );
painter->drawText( textR, text );
} else { // this is an existing account to show
// draw checkbox first
int pos = ( mid ) - ( iconSize / 2 );
QRect checkRect = QRect( checkLeftEdge, pos + top, iconSize, iconSize );
opt.rect = checkRect;
drawCheckBox( opt, painter, w );
// draw the icon if it exists
pos = ( mid ) - ( iconSize / 2 );
if( !index.data( Qt::DecorationRole ).value< QIcon >().isNull() ) {
QRect prect = QRect( iconLeftEdge, pos + top, iconSize, iconSize );
painter->save();
painter->drawPixmap( prect, index.data( Qt::DecorationRole ).value< QIcon >().pixmap( prect.size() ) );
painter->restore();
}
// from the right edge--config status and online/offline
QRect confRect = QRect( itemRect.width() - iconSize - 2 * PADDING, mid - iconSize / 2 + top, iconSize, iconSize );
if( index.data( SipModel::HasConfig ).toBool() ) {
QStyleOptionToolButton topt;
topt.rect = confRect;
topt.pos = confRect.topLeft();
drawConfigWrench( painter, opt, topt );
}
// draw the online/offline status
int statusIconSize = 10;
int statusX = confRect.left() - 2*PADDING - statusIconSize;
QFont statusF = opt.font;
statusF.setPointSize( statusF.pointSize() - 2 );
QFontMetrics statusFM( statusF );
QPixmap p;
QString statusText;
if( index.data( SipModel::ConnectionStateRole ).toInt() == SipPlugin::Connected ) {
p = QPixmap( RESPATH "images/sipplugin-online.png" );
statusText = tr( "Online" );
} else {
p = QPixmap( RESPATH "images/sipplugin-offline.png" );
statusText = tr( "Offline" );
}
p = p.scaled( statusIconSize, statusIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter->drawPixmap( statusX, mid - statusIconSize / 2 + top, statusIconSize, statusIconSize, p );
int width = statusFM.width( statusText );
statusX = statusX - PADDING - width;
painter->save();
painter->setFont( statusF );
painter->drawText( QRect( statusX, mid - statusFM.height() / 2 + top, width, statusFM.height() ), statusText );
painter->restore();
// name
painter->save();
QFontMetrics namefm( name );
int nameHeight = namefm.boundingRect( "test" ).height();
// pos will the top-left point of the text rect
pos = mid - ( nameHeight / 2 );
// TODO bound with config icon and offline/online status
width = itemRect.width() - textLeftEdge;
if( !index.data( SipModel::ErrorString ).toString().isEmpty() ) { // error, show that too
QRect errorRect( textLeftEdge, mid + top, width, mid - PADDING );
QFontMetrics errorFm( error );
QString str = errorFm.elidedText( index.data( SipModel::ErrorString ).toString(), Qt::ElideRight, errorRect.width() );
painter->setFont( error );
painter->drawText( errorRect, str );
pos = mid - errorRect.height() - 2; // move the name rect up
}
QString nameStr = namefm.elidedText( index.data( Qt::DisplayRole ).toString(), Qt::ElideRight, width );
painter->setFont( name );
painter->drawText( QRect( textLeftEdge, pos + top, width, nameHeight ), nameStr );
painter->restore();
}
// from the right edge--config status and online/offline
QRect confRect = QRect( itemRect.width() - iconSize - 2 * PADDING, mid - iconSize / 2 + top, iconSize, iconSize );
if( index.data( SipModel::HasConfig ).toBool() ) {
QStyleOptionToolButton topt;
topt.rect = confRect;
topt.pos = confRect.topLeft();
drawConfigWrench( painter, opt, topt );
}
// draw the online/offline status
int statusIconSize = 10;
int statusX = confRect.left() - 2*PADDING - statusIconSize;
QFont statusF = opt.font;
statusF.setPointSize( statusF.pointSize() - 2 );
QFontMetrics statusFM( statusF );
QPixmap p;
QString statusText;
if( index.data( SipModel::ConnectionStateRole ).toInt() == SipPlugin::Connected ) {
p = QPixmap( RESPATH "images/sipplugin-online.png" );
statusText = tr( "Online" );
} else {
p = QPixmap( RESPATH "images/sipplugin-offline.png" );
statusText = tr( "Offline" );
}
p = p.scaled( statusIconSize, statusIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter->drawPixmap( statusX, mid - statusIconSize / 2 + top, statusIconSize, statusIconSize, p );
int width = statusFM.width( statusText );
statusX = statusX - PADDING - width;
painter->save();
painter->setFont( statusF );
painter->drawText( QRect( statusX, mid - statusFM.height() / 2 + top, width, statusFM.height() ), statusText );
painter->restore();
// name
painter->save();
leftEdge = leftEdge + iconSize + PADDING;
QFontMetrics namefm( name );
int nameHeight = namefm.boundingRect( "test" ).height();
// pos will the top-left point of the text rect
pos = mid - ( nameHeight / 2 );
// TODO bound with config icon and offline/online status
width = itemRect.width() - leftEdge;
if( !index.data( SipModel::ErrorString ).toString().isEmpty() ) { // error, show that too
QRect errorRect( leftEdge, mid + top, width, mid - PADDING );
QFontMetrics errorFm( error );
QString str = errorFm.elidedText( index.data( SipModel::ErrorString ).toString(), Qt::ElideRight, errorRect.width() );
painter->setFont( error );
painter->drawText( errorRect, str );
pos = mid - errorRect.height() - 2; // move the name rect up
}
QString nameStr = namefm.elidedText( index.data( Qt::DisplayRole ).toString(), Qt::ElideRight, width );
painter->setFont( name );
painter->drawText( QRect( leftEdge, pos + top, width, nameHeight ), nameStr );
painter->restore();
}
QSize
SipConfigDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
if( index.data( SipModel::FactoryRole ).toBool() || index.data( SipModel::FactoryItemRole ).toBool() ) { // this is the "add new account" row
// enough space for one line of text
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index );
int width = QStyledItemDelegate::sizeHint( option, index ).width();
QFont name = opt.font;
name.setPointSize( name.pointSize() + 1 );
name.setBold( true );
QFontMetrics sfm( name );
return QSize( width, 3 * PADDING + sfm.height() );
} else { // this is an existing account to show
return ConfigDelegateBase::sizeHint( option, index );
}
}
void
SipConfigDelegate::askedForEdit( const QModelIndex& idx )
{
emit openConfig( qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() ) );
}

View File

@ -21,6 +21,8 @@
#include "configdelegatebase.h"
class SipPlugin;
class SipPluginFactory;
class SipConfigDelegate : public ConfigDelegateBase
{
Q_OBJECT
@ -29,6 +31,14 @@ public:
virtual void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual bool editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
virtual QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private slots:
void askedForEdit( const QModelIndex& idx );
signals:
void sipFactoryClicked( SipPluginFactory* );
void openConfig( SipPlugin* );
};
#endif // SIPCONFIGDELEGATE_H