Commit 7ac856e3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 287180 - Missing Server Side Subscription context menu

FIXED-IN: 4.9
BUG: 287180
parent b098d1e0
......@@ -58,6 +58,7 @@
#include "imapaccount.h"
#include "imapidlemanager.h"
#include "resourcestate.h"
#include "subscriptiondialog.h"
#include "addcollectiontask.h"
#include "additemtask.h"
......@@ -218,6 +219,29 @@ void ImapResource::startConnect( const QVariant& )
Q_UNUSED( result );
}
int ImapResource::configureSubscription()
{
if( !m_pool->account() )
return -2;
const QString password = Settings::self()->password();
if ( password.isEmpty() )
return -1;
SubscriptionDialog *subscriptions = new SubscriptionDialog( 0, SubscriptionDialog::AllowToEnableSubscription );
subscriptions->setCaption( i18n( "Serverside Subscription..." ) );
subscriptions->connectAccount( *m_pool->account(), password );
subscriptions->setSubscriptionEnabled( Settings::self()->subscriptionEnabled() );
if(subscriptions->exec()) {
Settings::self()->setSubscriptionEnabled( subscriptions->subscriptionEnabled() );
Settings::self()->writeConfig();
emit configurationDialogAccepted();
reconnect();
}
delete subscriptions;
return 0;
}
void ImapResource::onConnectDone( int errorCode, const QString &errorString )
{
switch ( errorCode ) {
......
......@@ -60,6 +60,7 @@ public Q_SLOTS:
Q_SCRIPTABLE void requestManualExpunge( qint64 collectionId );
Q_SCRIPTABLE void setFastSyncEnabled( bool fastSync );
Q_SCRIPTABLE bool isFastSyncEnabled() const;
Q_SCRIPTABLE int configureSubscription();
protected Q_SLOTS:
void startIdleIfNeeded();
......
......@@ -67,7 +67,7 @@ protected:
SubscriptionDialog::SubscriptionDialog( QWidget *parent )
SubscriptionDialog::SubscriptionDialog( QWidget *parent, SubscriptionDialog::SubscriptionDialogOptions option )
: KDialog( parent ),
m_session( 0 ),
m_subscriptionChanged( false ),
......@@ -88,6 +88,9 @@ SubscriptionDialog::SubscriptionDialog( QWidget *parent )
mainWidget->setLayout(mainLayout);
setMainWidget( mainWidget );
m_enableSubscription = new QCheckBox( i18n( "Enable server-side subscriptions" ) );
mainLayout->addWidget(m_enableSubscription);
QHBoxLayout *filterBarLayout = new QHBoxLayout;
mainLayout->addLayout(filterBarLayout);
......@@ -118,7 +121,7 @@ SubscriptionDialog::SubscriptionDialog( QWidget *parent )
connect( m_lineEdit, SIGNAL(textChanged(QString)),
this, SLOT(onMobileLineEditChanged(QString)) );
QListView *listView = new QListView( mainWidget );
QListView* listView = new QListView( mainWidget );
KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( listView );
flatModel->setDisplayAncestorData( true );
......@@ -139,8 +142,33 @@ SubscriptionDialog::SubscriptionDialog( QWidget *parent )
connect( m_model, SIGNAL(itemChanged(QStandardItem*)),
this, SLOT(onItemChanged(QStandardItem*)) );
if ( option & SubscriptionDialog::AllowToEnableSubscription ) {
#ifndef KDEPIM_MOBILE_UI
connect( m_enableSubscription, SIGNAL( clicked ( bool ) ), treeView, SLOT( setEnabled(bool) ) );
#else
connect( m_enableSubscription, SIGNAL( clicked ( bool ) ), listView, SLOT( setEnabled(bool) ) );
#endif
} else {
m_enableSubscription->hide();
}
}
SubscriptionDialog::~SubscriptionDialog()
{
}
void SubscriptionDialog::setSubscriptionEnabled( bool enabled )
{
m_enableSubscription->setChecked( enabled );
}
bool SubscriptionDialog::subscriptionEnabled() const
{
return m_enableSubscription->isChecked();
}
void SubscriptionDialog::connectAccount( const ImapAccount &account, const QString &password )
{
m_session = new KIMAP::Session( account.server(), account.port(), this );
......@@ -157,7 +185,7 @@ void SubscriptionDialog::connectAccount( const ImapAccount &account, const QStri
login->start();
}
bool SubscriptionDialog::isSubscriptionChanged()
bool SubscriptionDialog::isSubscriptionChanged() const
{
return m_subscriptionChanged;
}
......
......@@ -35,7 +35,7 @@ class QStandardItem;
class KDescendantsProxyModel;
class KLineEdit;
class QCheckBox;
class ImapAccount;
class SubscriptionFilterProxyModel : public KRecursiveFilterProxyModel
......@@ -66,11 +66,19 @@ public:
InitialStateRole = Qt::UserRole + 1,
PathRole
};
enum SubscriptionDialogOption {
None = 0,
AllowToEnableSubscription = 1
};
Q_DECLARE_FLAGS( SubscriptionDialogOptions, SubscriptionDialogOption )
explicit SubscriptionDialog( QWidget *parent = 0 );
explicit SubscriptionDialog( QWidget *parent = 0, SubscriptionDialog::SubscriptionDialogOptions option = SubscriptionDialog::None );
~SubscriptionDialog();
void connectAccount( const ImapAccount &account, const QString &password );
bool isSubscriptionChanged();
bool isSubscriptionChanged() const;
void setSubscriptionEnabled( bool enabled );
bool subscriptionEnabled() const;
private slots:
void onLoginDone( KJob *job );
......@@ -89,7 +97,6 @@ protected:
protected slots:
void slotButtonClicked( int button );
private:
void applyChanges();
......@@ -97,6 +104,7 @@ private:
bool m_subscriptionChanged;
KLineEdit *m_lineEdit;
QCheckBox *m_enableSubscription;
SubscriptionFilterProxyModel *m_filter;
KDescendantsProxyModel *m_flatModel;
QStandardItemModel *m_model;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment