You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
794 lines
22 KiB
794 lines
22 KiB
15 years ago
|
/*
|
||
|
ksubscription.cpp
|
||
|
|
||
|
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.
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software Foundation,
|
||
|
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
|
||
|
*/
|
||
|
|
||
|
#include "ksubscription.h"
|
||
|
#include "kaccount.h"
|
||
|
|
||
15 years ago
|
#include <tqlayout.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqheader.h>
|
||
|
#include <tqtoolbutton.h>
|
||
15 years ago
|
|
||
|
#include <kseparator.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <klineedit.h>
|
||
|
|
||
|
|
||
|
//=============================================================================
|
||
|
|
||
15 years ago
|
KGroupInfo::KGroupInfo(const TQString &name, const TQString &description,
|
||
15 years ago
|
bool newGroup, bool subscribed,
|
||
14 years ago
|
tqStatus status, TQString path)
|
||
15 years ago
|
: name(name), description(description),
|
||
|
newGroup(newGroup), subscribed(subscribed),
|
||
|
status(status), path(path)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
bool KGroupInfo::operator== (const KGroupInfo &gi2)
|
||
|
{
|
||
|
return (name == gi2.name);
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
bool KGroupInfo::operator< (const KGroupInfo &gi2)
|
||
|
{
|
||
|
return (name < gi2.name);
|
||
|
}
|
||
|
|
||
|
//=============================================================================
|
||
|
|
||
15 years ago
|
GroupItem::GroupItem( TQListView *v, const KGroupInfo &gi, KSubscription* browser,
|
||
15 years ago
|
bool isCheckItem )
|
||
15 years ago
|
: TQCheckListItem( v, gi.name, isCheckItem ? CheckBox : CheckBoxController ),
|
||
15 years ago
|
mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ),
|
||
|
mIgnoreStateChange( false )
|
||
|
{
|
||
|
if (listView()->columns() > 1)
|
||
|
setDescription();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
GroupItem::GroupItem( TQListViewItem *i, const KGroupInfo &gi, KSubscription* browser,
|
||
15 years ago
|
bool isCheckItem )
|
||
15 years ago
|
: TQCheckListItem( i, gi.name, isCheckItem ? CheckBox : CheckBoxController ),
|
||
15 years ago
|
mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ),
|
||
|
mIgnoreStateChange( false )
|
||
|
{
|
||
|
if (listView()->columns() > 1)
|
||
|
setDescription();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void GroupItem::setInfo( KGroupInfo info )
|
||
|
{
|
||
|
mInfo = info;
|
||
|
setText(0, mInfo.name);
|
||
|
if (listView()->columns() > 1)
|
||
|
setDescription();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void GroupItem::setDescription()
|
||
|
{
|
||
|
setText(1, mInfo.description);
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void GroupItem::setOn( bool on )
|
||
|
{
|
||
|
if (mBrowser->isLoading())
|
||
|
{
|
||
|
// set this only if we're loading/creating items
|
||
|
// otherwise changes are only permanent when the dialog is saved
|
||
|
mInfo.subscribed = on;
|
||
|
}
|
||
|
if (isCheckItem())
|
||
15 years ago
|
TQCheckListItem::setOn(on);
|
||
15 years ago
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void GroupItem::stateChange( bool on )
|
||
|
{
|
||
14 years ago
|
// delegate to parent
|
||
15 years ago
|
if ( !mIgnoreStateChange )
|
||
|
mBrowser->changeItemState(this, on);
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void GroupItem::setVisible( bool b )
|
||
|
{
|
||
|
if (b)
|
||
|
{
|
||
15 years ago
|
TQListViewItem::setVisible(b);
|
||
15 years ago
|
setEnabled(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (isCheckItem())
|
||
|
{
|
||
|
bool setInvisible = true;
|
||
15 years ago
|
for (TQListViewItem * lvchild = firstChild(); lvchild != 0;
|
||
15 years ago
|
lvchild = lvchild->nextSibling())
|
||
|
{
|
||
|
if (lvchild->isVisible()) // item has a visible child
|
||
|
setInvisible = false;
|
||
|
}
|
||
|
if (setInvisible)
|
||
15 years ago
|
TQListViewItem::setVisible(b);
|
||
15 years ago
|
else
|
||
|
{
|
||
14 years ago
|
// leave it visible so that tqchildren remain visible
|
||
15 years ago
|
setOpen(true);
|
||
|
setEnabled(false);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// non-checkable item
|
||
15 years ago
|
TQPtrList<TQListViewItem> moveItems;
|
||
15 years ago
|
|
||
15 years ago
|
for (TQListViewItem * lvchild = firstChild(); lvchild != 0;
|
||
15 years ago
|
lvchild = lvchild->nextSibling())
|
||
|
{
|
||
|
if (static_cast<GroupItem*>(lvchild)->isCheckItem())
|
||
|
{
|
||
|
// remember the items
|
||
|
moveItems.append(lvchild);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
TQPtrListIterator<TQListViewItem> it( moveItems );
|
||
15 years ago
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
// move the checkitem to top
|
||
14 years ago
|
TQListViewItem* parent = it.current()->parent();
|
||
|
if (parent) parent->takeItem(it.current());
|
||
15 years ago
|
listView()->insertItem(it.current());
|
||
|
}
|
||
15 years ago
|
TQListViewItem::setVisible(false);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void GroupItem::paintCell( TQPainter * p, const TQColorGroup & cg,
|
||
15 years ago
|
int column, int width, int align )
|
||
|
{
|
||
|
if (mIsCheckItem)
|
||
15 years ago
|
return TQCheckListItem::paintCell( p, cg, column, width, align );
|
||
15 years ago
|
else
|
||
15 years ago
|
return TQListViewItem::paintCell( p, cg, column, width, align );
|
||
15 years ago
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void GroupItem::paintFocus( TQPainter * p, const TQColorGroup & cg,
|
||
|
const TQRect & r )
|
||
15 years ago
|
{
|
||
|
if (mIsCheckItem)
|
||
15 years ago
|
TQCheckListItem::paintFocus(p, cg, r);
|
||
15 years ago
|
else
|
||
15 years ago
|
TQListViewItem::paintFocus(p, cg, r);
|
||
15 years ago
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
int GroupItem::width( const TQFontMetrics& fm, const TQListView* lv, int column) const
|
||
15 years ago
|
{
|
||
|
if (mIsCheckItem)
|
||
15 years ago
|
return TQCheckListItem::width(fm, lv, column);
|
||
15 years ago
|
else
|
||
15 years ago
|
return TQListViewItem::width(fm, lv, column);
|
||
15 years ago
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void GroupItem::setup()
|
||
|
{
|
||
|
if (mIsCheckItem)
|
||
15 years ago
|
TQCheckListItem::setup();
|
||
15 years ago
|
else
|
||
15 years ago
|
TQListViewItem::setup();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
//=============================================================================
|
||
|
|
||
14 years ago
|
KSubscription::KSubscription( TQWidget *parent, const TQString &caption,
|
||
15 years ago
|
KAccount * acct, int buttons, const TQString &user1, bool descriptionColumn )
|
||
14 years ago
|
: KDialogBase( parent, 0, true, caption, buttons | Help | Ok | Cancel, Ok,
|
||
15 years ago
|
true, i18n("Reload &List"), user1 ),
|
||
|
mAcct( acct )
|
||
|
{
|
||
|
mLoading = true;
|
||
|
setWFlags( getWFlags() | WDestructiveClose );
|
||
|
|
||
|
// create Widgets
|
||
15 years ago
|
page = new TQWidget(this);
|
||
15 years ago
|
setMainWidget(page);
|
||
|
|
||
15 years ago
|
TQLabel *comment = new TQLabel("<p>"+
|
||
15 years ago
|
i18n("Manage which mail folders you want to see in your folder view") + "</p>", page);
|
||
|
|
||
15 years ago
|
TQToolButton *clearButton = new TQToolButton( page );
|
||
15 years ago
|
clearButton->setIconSet( KGlobal::iconLoader()->loadIconSet(
|
||
|
KApplication::reverseLayout() ? "clear_left":"locationbar_erase", KIcon::Small, 0 ) );
|
||
|
filterEdit = new KLineEdit(page);
|
||
15 years ago
|
TQLabel *l = new TQLabel(filterEdit,i18n("S&earch:"), page);
|
||
|
connect( clearButton, TQT_SIGNAL( clicked() ), filterEdit, TQT_SLOT( clear() ) );
|
||
15 years ago
|
|
||
|
// checkboxes
|
||
15 years ago
|
noTreeCB = new TQCheckBox(i18n("Disable &tree view"), page);
|
||
15 years ago
|
noTreeCB->setChecked(false);
|
||
15 years ago
|
subCB = new TQCheckBox(i18n("&Subscribed only"), page);
|
||
15 years ago
|
subCB->setChecked(false);
|
||
15 years ago
|
newCB = new TQCheckBox(i18n("&New only"), page);
|
||
15 years ago
|
newCB->setChecked(false);
|
||
|
|
||
|
|
||
|
KSeparator *sep = new KSeparator(KSeparator::HLine, page);
|
||
|
|
||
|
// init the labels
|
||
15 years ago
|
TQFont fnt = font();
|
||
15 years ago
|
fnt.setBold(true);
|
||
15 years ago
|
leftLabel = new TQLabel(i18n("Loading..."), page);
|
||
|
rightLabel = new TQLabel(i18n("Current changes:"), page);
|
||
15 years ago
|
leftLabel->setFont(fnt);
|
||
|
rightLabel->setFont(fnt);
|
||
|
|
||
|
// icons
|
||
|
pmRight = BarIconSet("forward");
|
||
|
pmLeft = BarIconSet("back");
|
||
|
|
||
15 years ago
|
arrowBtn1 = new TQPushButton(page);
|
||
15 years ago
|
arrowBtn1->setEnabled(false);
|
||
15 years ago
|
arrowBtn2 = new TQPushButton(page);
|
||
15 years ago
|
arrowBtn2->setEnabled(false);
|
||
|
arrowBtn1->setIconSet(pmRight);
|
||
|
arrowBtn2->setIconSet(pmRight);
|
||
|
arrowBtn1->setFixedSize(35,30);
|
||
|
arrowBtn2->setFixedSize(35,30);
|
||
|
|
||
|
// the main listview
|
||
15 years ago
|
groupView = new TQListView(page);
|
||
15 years ago
|
groupView->setRootIsDecorated(true);
|
||
|
groupView->addColumn(i18n("Name"));
|
||
|
groupView->setAllColumnsShowFocus(true);
|
||
|
if (descriptionColumn)
|
||
|
mDescrColumn = groupView->addColumn(i18n("Description"));
|
||
|
else
|
||
|
groupView->header()->setStretchEnabled(true, 0);
|
||
|
|
||
14 years ago
|
// tqlayout
|
||
15 years ago
|
TQGridLayout *topL = new TQGridLayout(page,4,1,0, KDialog::spacingHint());
|
||
|
TQHBoxLayout *filterL = new TQHBoxLayout(KDialog::spacingHint());
|
||
|
TQVBoxLayout *arrL = new TQVBoxLayout(KDialog::spacingHint());
|
||
|
listL = new TQGridLayout(2, 3, KDialog::spacingHint());
|
||
15 years ago
|
|
||
|
topL->addWidget(comment, 0,0);
|
||
|
topL->addLayout(filterL, 1,0);
|
||
|
topL->addWidget(sep,2,0);
|
||
|
topL->addLayout(listL, 3,0);
|
||
|
|
||
|
filterL->addWidget(clearButton);
|
||
|
filterL->addWidget(l);
|
||
|
filterL->addWidget(filterEdit, 1);
|
||
|
filterL->addWidget(noTreeCB);
|
||
|
filterL->addWidget(subCB);
|
||
|
filterL->addWidget(newCB);
|
||
|
|
||
|
listL->addWidget(leftLabel, 0,0);
|
||
|
listL->addWidget(rightLabel, 0,2);
|
||
|
listL->addWidget(groupView, 1,0);
|
||
|
listL->addLayout(arrL, 1,1);
|
||
|
listL->setRowStretch(1,1);
|
||
|
listL->setColStretch(0,5);
|
||
|
listL->setColStretch(2,2);
|
||
|
|
||
|
arrL->addWidget(arrowBtn1, AlignCenter);
|
||
|
arrL->addWidget(arrowBtn2, AlignCenter);
|
||
|
|
||
|
// listviews
|
||
15 years ago
|
subView = new TQListView(page);
|
||
15 years ago
|
subView->addColumn(i18n("Subscribe To"));
|
||
|
subView->header()->setStretchEnabled(true, 0);
|
||
15 years ago
|
unsubView = new TQListView(page);
|
||
15 years ago
|
unsubView->addColumn(i18n("Unsubscribe From"));
|
||
|
unsubView->header()->setStretchEnabled(true, 0);
|
||
|
|
||
15 years ago
|
TQVBoxLayout *protL = new TQVBoxLayout(3);
|
||
15 years ago
|
listL->addLayout(protL, 1,2);
|
||
|
protL->addWidget(subView);
|
||
|
protL->addWidget(unsubView);
|
||
|
|
||
|
// disable some widgets as long we're loading
|
||
|
enableButton(User1, false);
|
||
|
enableButton(User2, false);
|
||
|
newCB->setEnabled(false);
|
||
|
noTreeCB->setEnabled(false);
|
||
|
subCB->setEnabled(false);
|
||
|
|
||
|
filterEdit->setFocus();
|
||
|
|
||
|
// items clicked
|
||
15 years ago
|
connect(groupView, TQT_SIGNAL(clicked(TQListViewItem *)),
|
||
|
this, TQT_SLOT(slotChangeButtonState(TQListViewItem*)));
|
||
|
connect(subView, TQT_SIGNAL(clicked(TQListViewItem *)),
|
||
|
this, TQT_SLOT(slotChangeButtonState(TQListViewItem*)));
|
||
|
connect(unsubView, TQT_SIGNAL(clicked(TQListViewItem *)),
|
||
|
this, TQT_SLOT(slotChangeButtonState(TQListViewItem*)));
|
||
15 years ago
|
|
||
|
// connect buttons
|
||
15 years ago
|
connect(arrowBtn1, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton1()));
|
||
|
connect(arrowBtn2, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton2()));
|
||
|
connect(this, TQT_SIGNAL(user1Clicked()), TQT_SLOT(slotLoadFolders()));
|
||
15 years ago
|
|
||
|
// connect checkboxes
|
||
15 years ago
|
connect(subCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled()));
|
||
|
connect(newCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled()));
|
||
|
connect(noTreeCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled()));
|
||
15 years ago
|
|
||
|
// connect textfield
|
||
15 years ago
|
connect(filterEdit, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
TQT_SLOT(slotFilterTextChanged(const TQString&)));
|
||
15 years ago
|
|
||
|
// update status
|
||
15 years ago
|
connect(this, TQT_SIGNAL(listChanged()), TQT_SLOT(slotUpdateStatusLabel()));
|
||
15 years ago
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
KSubscription::~KSubscription()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void KSubscription::setStartItem( const KGroupInfo &info )
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
if (static_cast<GroupItem*>(it.current())->info() == info)
|
||
|
{
|
||
|
it.current()->setSelected(true);
|
||
|
it.current()->setOpen(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void KSubscription::removeListItem( TQListView *view, const KGroupInfo &gi )
|
||
15 years ago
|
{
|
||
|
if(!view) return;
|
||
15 years ago
|
TQListViewItemIterator it(view);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
if (static_cast<GroupItem*>(it.current())->info() == gi)
|
||
|
{
|
||
|
delete it.current();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (view == groupView)
|
||
|
emit listChanged();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
TQListViewItem* KSubscription::getListItem( TQListView *view, const KGroupInfo &gi )
|
||
15 years ago
|
{
|
||
|
if(!view) return 0;
|
||
15 years ago
|
TQListViewItemIterator it(view);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
if (static_cast<GroupItem*>(it.current())->info() == gi)
|
||
|
return (it.current());
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
bool KSubscription::itemInListView( TQListView *view, const KGroupInfo &gi )
|
||
15 years ago
|
{
|
||
|
if(!view) return false;
|
||
15 years ago
|
TQListViewItemIterator it(view);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
if (static_cast<GroupItem*>(it.current())->info() == gi)
|
||
|
return true;
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::setDirectionButton1( Direction dir )
|
||
|
{
|
||
|
mDirButton1 = dir;
|
||
|
if (dir == Left)
|
||
|
arrowBtn1->setIconSet(pmLeft);
|
||
|
else
|
||
|
arrowBtn1->setIconSet(pmRight);
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::setDirectionButton2( Direction dir )
|
||
|
{
|
||
|
mDirButton2 = dir;
|
||
|
if (dir == Left)
|
||
|
arrowBtn2->setIconSet(pmLeft);
|
||
|
else
|
||
|
arrowBtn2->setIconSet(pmRight);
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::changeItemState( GroupItem* item, bool on )
|
||
|
{
|
||
|
// is this a checkable item
|
||
|
if (!item->isCheckItem()) return;
|
||
|
|
||
|
// if we're currently loading the items ignore changes
|
||
|
if (mLoading) return;
|
||
|
if (on)
|
||
|
{
|
||
|
if (!itemInListView(unsubView, item->info()))
|
||
|
{
|
||
14 years ago
|
TQListViewItem *p = item->parent();
|
||
15 years ago
|
while (p)
|
||
|
{
|
||
14 years ago
|
// make sure all parents are subscribed
|
||
15 years ago
|
GroupItem* pi = static_cast<GroupItem*>(p);
|
||
|
if (pi->isCheckItem() && !pi->isOn())
|
||
|
{
|
||
|
pi->setIgnoreStateChange(true);
|
||
|
pi->setOn(true);
|
||
|
pi->setIgnoreStateChange(false);
|
||
|
new GroupItem(subView, pi->info(), this);
|
||
|
}
|
||
14 years ago
|
p = p->parent();
|
||
15 years ago
|
}
|
||
|
new GroupItem(subView, item->info(), this);
|
||
|
}
|
||
|
// eventually remove it from the other listview
|
||
|
removeListItem(unsubView, item->info());
|
||
|
}
|
||
|
else {
|
||
|
if (!itemInListView(subView, item->info()))
|
||
|
{
|
||
|
new GroupItem(unsubView, item->info(), this);
|
||
|
}
|
||
|
// eventually remove it from the other listview
|
||
|
removeListItem(subView, item->info());
|
||
|
}
|
||
|
// update the buttons
|
||
|
slotChangeButtonState(item);
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
15 years ago
|
void KSubscription::filterChanged( TQListViewItem* item, const TQString & text )
|
||
15 years ago
|
{
|
||
|
if ( !item && groupView )
|
||
|
item = groupView->firstChild();
|
||
|
if ( !item )
|
||
|
return;
|
||
|
|
||
|
do
|
||
|
{
|
||
|
if ( item->firstChild() ) // recursive descend
|
||
|
filterChanged(item->firstChild(), text);
|
||
|
|
||
|
GroupItem* gr = static_cast<GroupItem*>(item);
|
||
|
if (subCB->isChecked() || newCB->isChecked() || !text.isEmpty() ||
|
||
|
noTreeCB->isChecked())
|
||
|
{
|
||
|
// set it invisible
|
||
|
if ( subCB->isChecked() &&
|
||
|
(!gr->isCheckItem() ||
|
||
|
(gr->isCheckItem() && !gr->info().subscribed)) )
|
||
|
{
|
||
|
// only subscribed
|
||
|
gr->setVisible(false);
|
||
|
continue;
|
||
|
}
|
||
|
if ( newCB->isChecked() &&
|
||
|
(!gr->isCheckItem() ||
|
||
|
(gr->isCheckItem() && !gr->info().newGroup)) )
|
||
|
{
|
||
|
// only new
|
||
|
gr->setVisible(false);
|
||
|
continue;
|
||
|
}
|
||
|
if ( !text.isEmpty() &&
|
||
14 years ago
|
gr->text(0).find(text, 0, false) == -1)
|
||
15 years ago
|
{
|
||
|
// searchfield
|
||
|
gr->setVisible(false);
|
||
|
continue;
|
||
|
}
|
||
|
if ( noTreeCB->isChecked() &&
|
||
|
!gr->isCheckItem() )
|
||
|
{
|
||
|
// disable treeview
|
||
|
gr->setVisible(false);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
gr->setVisible(true);
|
||
|
|
||
|
} else {
|
||
|
gr->setVisible(true);
|
||
|
}
|
||
|
|
||
|
} while ((item = item->nextSibling()));
|
||
|
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
uint KSubscription::activeItemCount()
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
|
||
|
uint count = 0;
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
if (static_cast<GroupItem*>(it.current())->isCheckItem() &&
|
||
|
it.current()->isVisible() && it.current()->isEnabled())
|
||
|
count++;
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::restoreOriginalParent()
|
||
|
{
|
||
15 years ago
|
TQPtrList<TQListViewItem> move;
|
||
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
15 years ago
|
TQListViewItem* origParent = static_cast<GroupItem*>(it.current())->
|
||
15 years ago
|
originalParent();
|
||
14 years ago
|
if (origParent && origParent != it.current()->parent())
|
||
15 years ago
|
{
|
||
|
// remember this to avoid messing up the iterator
|
||
|
move.append(it.current());
|
||
|
}
|
||
|
}
|
||
15 years ago
|
TQPtrListIterator<TQListViewItem> it2( move );
|
||
15 years ago
|
for ( ; it2.current(); ++it2)
|
||
|
{
|
||
14 years ago
|
// restore the original parent
|
||
15 years ago
|
TQListViewItem* origParent = static_cast<GroupItem*>(it2.current())->
|
||
15 years ago
|
originalParent();
|
||
|
groupView->takeItem(it2.current());
|
||
|
origParent->insertItem(it2.current());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void KSubscription::saveOpenStates()
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
static_cast<GroupItem*>(it.current())->setLastOpenState(
|
||
|
it.current()->isOpen() );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void KSubscription::restoreOpenStates()
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
|
||
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
it.current()->setOpen(
|
||
|
static_cast<GroupItem*>(it.current())->lastOpenState() );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void KSubscription::slotLoadingComplete()
|
||
|
{
|
||
|
mLoading = false;
|
||
|
|
||
|
enableButton(User1, true);
|
||
|
enableButton(User2, true);
|
||
|
newCB->setEnabled(true);
|
||
|
noTreeCB->setEnabled(true);
|
||
|
subCB->setEnabled(true);
|
||
|
|
||
14 years ago
|
// remember the correct parent
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
static_cast<GroupItem*>(it.current())->
|
||
14 years ago
|
setOriginalParent( it.current()->parent() );
|
||
15 years ago
|
}
|
||
|
|
||
|
emit listChanged();
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
15 years ago
|
void KSubscription::slotChangeButtonState( TQListViewItem *item )
|
||
15 years ago
|
{
|
||
|
if (!item ||
|
||
|
(item->listView() == groupView &&
|
||
|
!static_cast<GroupItem*>(item)->isCheckItem()))
|
||
|
{
|
||
|
// disable and return
|
||
|
arrowBtn1->setEnabled(false);
|
||
|
arrowBtn2->setEnabled(false);
|
||
|
return;
|
||
|
}
|
||
|
// set the direction of the buttons and enable/disable them
|
||
15 years ago
|
TQListView* currentView = item->listView();
|
||
15 years ago
|
if (currentView == groupView)
|
||
|
{
|
||
|
setDirectionButton1(Right);
|
||
|
setDirectionButton2(Right);
|
||
|
if (static_cast<GroupItem*>(item)->isOn())
|
||
|
{
|
||
|
// already subscribed
|
||
|
arrowBtn1->setEnabled(false);
|
||
|
arrowBtn2->setEnabled(true);
|
||
|
} else {
|
||
|
// unsubscribed
|
||
|
arrowBtn1->setEnabled(true);
|
||
|
arrowBtn2->setEnabled(false);
|
||
|
}
|
||
|
} else if (currentView == subView)
|
||
|
{
|
||
|
// undo possible
|
||
|
setDirectionButton1(Left);
|
||
|
|
||
|
arrowBtn1->setEnabled(true);
|
||
|
arrowBtn2->setEnabled(false);
|
||
|
} else if (currentView == unsubView)
|
||
|
{
|
||
|
// undo possible
|
||
|
setDirectionButton2(Left);
|
||
|
|
||
|
arrowBtn1->setEnabled(false);
|
||
|
arrowBtn2->setEnabled(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::slotButton1()
|
||
|
{
|
||
|
if (mDirButton1 == Right)
|
||
|
{
|
||
|
if (groupView->currentItem() &&
|
||
|
static_cast<GroupItem*>(groupView->currentItem())->isCheckItem())
|
||
|
{
|
||
|
// activate
|
||
|
GroupItem* item = static_cast<GroupItem*>(groupView->currentItem());
|
||
|
item->setOn(true);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (subView->currentItem())
|
||
|
{
|
||
|
GroupItem* item = static_cast<GroupItem*>(subView->currentItem());
|
||
|
// get the corresponding item from the groupView
|
||
15 years ago
|
TQListViewItem* listitem = getListItem(groupView, item->info());
|
||
15 years ago
|
if (listitem)
|
||
|
{
|
||
|
// deactivate
|
||
|
GroupItem* chk = static_cast<GroupItem*>(listitem);
|
||
|
chk->setOn(false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::slotButton2()
|
||
|
{
|
||
|
if (mDirButton2 == Right)
|
||
|
{
|
||
|
if (groupView->currentItem() &&
|
||
|
static_cast<GroupItem*>(groupView->currentItem())->isCheckItem())
|
||
|
{
|
||
|
// deactivate
|
||
|
GroupItem* item = static_cast<GroupItem*>(groupView->currentItem());
|
||
|
item->setOn(false);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (unsubView->currentItem())
|
||
|
{
|
||
|
GroupItem* item = static_cast<GroupItem*>(unsubView->currentItem());
|
||
|
// get the corresponding item from the groupView
|
||
15 years ago
|
TQListViewItem* listitem = getListItem(groupView, item->info());
|
||
15 years ago
|
if (listitem)
|
||
|
{
|
||
|
// activate
|
||
|
GroupItem* chk = static_cast<GroupItem*>(listitem);
|
||
|
chk->setOn(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::slotCBToggled()
|
||
|
{
|
||
|
if (!noTreeCB->isChecked() && !newCB->isChecked() && !subCB->isChecked())
|
||
|
{
|
||
|
restoreOriginalParent();
|
||
|
}
|
||
|
// set items {in}visible
|
||
|
filterChanged(groupView->firstChild());
|
||
|
emit listChanged();
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
15 years ago
|
void KSubscription::slotFilterTextChanged( const TQString & text )
|
||
15 years ago
|
{
|
||
|
// remember is the items are open
|
||
|
if (mLastText.isEmpty())
|
||
|
saveOpenStates();
|
||
|
|
||
|
if (!mLastText.isEmpty() && text.length() < mLastText.length())
|
||
|
{
|
||
|
// reset
|
||
|
restoreOriginalParent();
|
||
15 years ago
|
TQListViewItemIterator it(groupView);
|
||
15 years ago
|
for ( ; it.current(); ++it)
|
||
|
{
|
||
|
it.current()->setVisible(true);
|
||
|
it.current()->setEnabled(true);
|
||
|
}
|
||
|
}
|
||
|
// set items {in}visible
|
||
|
filterChanged(groupView->firstChild(), text);
|
||
|
// restore the open-states
|
||
|
if (text.isEmpty())
|
||
|
restoreOpenStates();
|
||
|
|
||
|
emit listChanged();
|
||
|
mLastText = text;
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::slotUpdateStatusLabel()
|
||
|
{
|
||
15 years ago
|
TQString text;
|
||
15 years ago
|
if (mLoading)
|
||
|
text = i18n("Loading... (1 matching)", "Loading... (%n matching)",
|
||
|
activeItemCount());
|
||
|
else
|
||
|
text = i18n("%1: (1 matching)", "%1: (%n matching)", activeItemCount())
|
||
14 years ago
|
.tqarg(account()->name());
|
||
15 years ago
|
|
||
|
leftLabel->setText(text);
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
void KSubscription::slotLoadFolders()
|
||
|
{
|
||
|
enableButton(User1, false);
|
||
|
mLoading = true;
|
||
|
subView->clear();
|
||
|
unsubView->clear();
|
||
|
groupView->clear();
|
||
|
}
|
||
|
|
||
|
#include "ksubscription.moc"
|