19 #include <tqpushbutton.h>
21 #include <tqtoolbutton.h>
23 #include <kseparator.h>
24 #include <tdeapplication.h>
25 #include <kiconloader.h>
26 #include <tdelocale.h>
28 #include <klineedit.h>
33 KGroupInfo::KGroupInfo(
const TQString &name,
const TQString &description,
34 bool newGroup,
bool subscribed,
35 Status status, TQString path)
36 : name(name), description(description),
37 newGroup(newGroup), subscribed(subscribed),
38 status(status), path(path)
43 bool KGroupInfo::operator== (
const KGroupInfo &gi2)
45 return (name == gi2.name);
49 bool KGroupInfo::operator< (
const KGroupInfo &gi2)
51 return (name < gi2.name);
56 GroupItem::GroupItem( TQListView *v,
const KGroupInfo &gi,
KSubscription* browser,
58 : TQCheckListItem( v, gi.name, isCheckItem ? CheckBox : CheckBoxController ),
59 mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ),
60 mIgnoreStateChange( false )
62 if (listView()->columns() > 1)
67 GroupItem::GroupItem( TQListViewItem *i,
const KGroupInfo &gi,
KSubscription* browser,
69 : TQCheckListItem( i, gi.name, isCheckItem ? CheckBox : CheckBoxController ),
70 mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ),
71 mIgnoreStateChange( false )
73 if (listView()->columns() > 1)
78 void GroupItem::setInfo( KGroupInfo info )
81 setText(0, mInfo.name);
82 if (listView()->columns() > 1)
89 setText(1, mInfo.description);
99 mInfo.subscribed = on;
102 TQCheckListItem::setOn(on);
109 if ( !mIgnoreStateChange )
118 TQListViewItem::setVisible(b);
125 bool setInvisible =
true;
126 for (TQListViewItem * lvchild = firstChild(); lvchild != 0;
127 lvchild = lvchild->nextSibling())
129 if (lvchild->isVisible())
130 setInvisible =
false;
133 TQListViewItem::setVisible(b);
144 TQPtrList<TQListViewItem> moveItems;
146 for (TQListViewItem * lvchild = firstChild(); lvchild != 0;
147 lvchild = lvchild->nextSibling())
152 moveItems.append(lvchild);
155 TQPtrListIterator<TQListViewItem> it( moveItems );
156 for ( ; it.current(); ++it)
159 TQListViewItem* parent = it.current()->parent();
160 if (parent) parent->takeItem(it.current());
161 listView()->insertItem(it.current());
163 TQListViewItem::setVisible(
false);
170 int column,
int width,
int align )
173 return TQCheckListItem::paintCell( p, cg, column,
width, align );
175 return TQListViewItem::paintCell( p, cg, column,
width, align );
183 TQCheckListItem::paintFocus(p, cg, r);
185 TQListViewItem::paintFocus(p, cg, r);
192 return TQCheckListItem::width(fm, lv, column);
194 return TQListViewItem::width(fm, lv, column);
201 TQCheckListItem::setup();
203 TQListViewItem::setup();
209 KSubscription::KSubscription( TQWidget *parent,
const TQString &caption,
210 KAccount * acct,
int buttons,
const TQString &user1,
bool descriptionColumn )
211 : KDialogBase( parent, 0, true, caption, buttons | Help | Ok | Cancel, Ok,
212 true, i18n(
"Reload &List"), user1 ),
216 setWFlags( getWFlags() | WDestructiveClose );
219 page =
new TQWidget(
this);
222 TQLabel *comment =
new TQLabel(
"<p>"+
223 i18n(
"Manage which mail folders you want to see in your folder view") +
"</p>", page);
225 TQToolButton *clearButton =
new TQToolButton( page );
226 clearButton->setIconSet( TDEGlobal::iconLoader()->loadIconSet(
227 TDEApplication::reverseLayout() ?
"clear_left":
"locationbar_erase", TDEIcon::Small, 0 ) );
228 filterEdit =
new KLineEdit(page);
229 TQLabel *l =
new TQLabel(filterEdit,i18n(
"S&earch:"), page);
230 connect( clearButton, TQ_SIGNAL( clicked() ), filterEdit, TQ_SLOT( clear() ) );
233 noTreeCB =
new TQCheckBox(i18n(
"Disable &tree view"), page);
234 noTreeCB->setChecked(
false);
235 subCB =
new TQCheckBox(i18n(
"&Subscribed only"), page);
236 subCB->setChecked(
false);
237 newCB =
new TQCheckBox(i18n(
"&New only"), page);
238 newCB->setChecked(
false);
241 KSeparator *sep =
new KSeparator(KSeparator::HLine, page);
246 leftLabel =
new TQLabel(i18n(
"Loading..."), page);
247 rightLabel =
new TQLabel(i18n(
"Current changes:"), page);
248 leftLabel->setFont(fnt);
249 rightLabel->setFont(fnt);
252 pmRight = BarIconSet(
"forward");
253 pmLeft = BarIconSet(
"back");
255 arrowBtn1 =
new TQPushButton(page);
256 arrowBtn1->setEnabled(
false);
257 arrowBtn2 =
new TQPushButton(page);
258 arrowBtn2->setEnabled(
false);
259 arrowBtn1->setIconSet(pmRight);
260 arrowBtn2->setIconSet(pmRight);
261 arrowBtn1->setFixedSize(35,30);
262 arrowBtn2->setFixedSize(35,30);
265 groupView =
new TQListView(page);
266 groupView->setRootIsDecorated(
true);
267 groupView->addColumn(i18n(
"Name"));
268 groupView->setAllColumnsShowFocus(
true);
269 if (descriptionColumn)
270 mDescrColumn = groupView->addColumn(i18n(
"Description"));
272 groupView->header()->setStretchEnabled(
true, 0);
275 TQGridLayout *topL =
new TQGridLayout(page,4,1,0, KDialog::spacingHint());
276 TQHBoxLayout *filterL =
new TQHBoxLayout(KDialog::spacingHint());
277 TQVBoxLayout *arrL =
new TQVBoxLayout(KDialog::spacingHint());
278 listL =
new TQGridLayout(2, 3, KDialog::spacingHint());
280 topL->addWidget(comment, 0,0);
281 topL->addLayout(filterL, 1,0);
282 topL->addWidget(sep,2,0);
283 topL->addLayout(listL, 3,0);
285 filterL->addWidget(clearButton);
286 filterL->addWidget(l);
287 filterL->addWidget(filterEdit, 1);
288 filterL->addWidget(noTreeCB);
289 filterL->addWidget(subCB);
290 filterL->addWidget(newCB);
292 listL->addWidget(leftLabel, 0,0);
293 listL->addWidget(rightLabel, 0,2);
294 listL->addWidget(groupView, 1,0);
295 listL->addLayout(arrL, 1,1);
296 listL->setRowStretch(1,1);
297 listL->setColStretch(0,5);
298 listL->setColStretch(2,2);
300 arrL->addWidget(arrowBtn1, AlignCenter);
301 arrL->addWidget(arrowBtn2, AlignCenter);
304 subView =
new TQListView(page);
305 subView->addColumn(i18n(
"Subscribe To"));
306 subView->header()->setStretchEnabled(
true, 0);
307 unsubView =
new TQListView(page);
308 unsubView->addColumn(i18n(
"Unsubscribe From"));
309 unsubView->header()->setStretchEnabled(
true, 0);
311 TQVBoxLayout *protL =
new TQVBoxLayout(3);
312 listL->addLayout(protL, 1,2);
313 protL->addWidget(subView);
314 protL->addWidget(unsubView);
317 enableButton(User1,
false);
318 enableButton(User2,
false);
319 newCB->setEnabled(
false);
320 noTreeCB->setEnabled(
false);
321 subCB->setEnabled(
false);
323 filterEdit->setFocus();
326 connect(groupView, TQ_SIGNAL(clicked(TQListViewItem *)),
327 this, TQ_SLOT(slotChangeButtonState(TQListViewItem*)));
328 connect(subView, TQ_SIGNAL(clicked(TQListViewItem *)),
329 this, TQ_SLOT(slotChangeButtonState(TQListViewItem*)));
330 connect(unsubView, TQ_SIGNAL(clicked(TQListViewItem *)),
331 this, TQ_SLOT(slotChangeButtonState(TQListViewItem*)));
334 connect(arrowBtn1, TQ_SIGNAL(clicked()), TQ_SLOT(slotButton1()));
335 connect(arrowBtn2, TQ_SIGNAL(clicked()), TQ_SLOT(slotButton2()));
336 connect(
this, TQ_SIGNAL(user1Clicked()), TQ_SLOT(slotLoadFolders()));
339 connect(subCB, TQ_SIGNAL(clicked()), TQ_SLOT(slotCBToggled()));
340 connect(newCB, TQ_SIGNAL(clicked()), TQ_SLOT(slotCBToggled()));
341 connect(noTreeCB, TQ_SIGNAL(clicked()), TQ_SLOT(slotCBToggled()));
344 connect(filterEdit, TQ_SIGNAL(textChanged(
const TQString&)),
345 TQ_SLOT(slotFilterTextChanged(
const TQString&)));
348 connect(
this, TQ_SIGNAL(listChanged()), TQ_SLOT(slotUpdateStatusLabel()));
352 KSubscription::~KSubscription()
359 TQListViewItemIterator it(groupView);
361 for ( ; it.current(); ++it)
365 it.current()->setSelected(
true);
366 it.current()->setOpen(
true);
375 TQListViewItemIterator it(view);
377 for ( ; it.current(); ++it)
385 if (view == groupView)
393 TQListViewItemIterator it(view);
395 for ( ; it.current(); ++it)
398 return (it.current());
406 if(!view)
return false;
407 TQListViewItemIterator it(view);
409 for ( ; it.current(); ++it)
417 void KSubscription::setDirectionButton1( Direction dir )
421 arrowBtn1->setIconSet(pmLeft);
423 arrowBtn1->setIconSet(pmRight);
427 void KSubscription::setDirectionButton2( Direction dir )
431 arrowBtn2->setIconSet(pmLeft);
433 arrowBtn2->setIconSet(pmRight);
443 if (mLoading)
return;
448 TQListViewItem *p = item->parent();
455 pi->setIgnoreStateChange(
true);
457 pi->setIgnoreStateChange(
false);
482 if ( !item && groupView )
483 item = groupView->firstChild();
489 if ( item->firstChild() )
493 if (subCB->isChecked() || newCB->isChecked() || !text.isEmpty() ||
494 noTreeCB->isChecked())
497 if ( subCB->isChecked() &&
505 if ( newCB->isChecked() &&
513 if ( !text.isEmpty() &&
514 gr->text(0).find(text, 0,
false) == -1)
520 if ( noTreeCB->isChecked() &&
534 }
while ((item = item->nextSibling()));
541 TQListViewItemIterator it(groupView);
544 for ( ; it.current(); ++it)
547 it.current()->isVisible() && it.current()->isEnabled())
557 TQPtrList<TQListViewItem> move;
558 TQListViewItemIterator it(groupView);
559 for ( ; it.current(); ++it)
561 TQListViewItem* origParent =
static_cast<GroupItem*
>(it.current())->
563 if (origParent && origParent != it.current()->parent())
566 move.append(it.current());
569 TQPtrListIterator<TQListViewItem> it2( move );
570 for ( ; it2.current(); ++it2)
573 TQListViewItem* origParent =
static_cast<GroupItem*
>(it2.current())->
575 groupView->takeItem(it2.current());
576 origParent->insertItem(it2.current());
583 TQListViewItemIterator it(groupView);
585 for ( ; it.current(); ++it)
587 static_cast<GroupItem*
>(it.current())->setLastOpenState(
588 it.current()->isOpen() );
595 TQListViewItemIterator it(groupView);
597 for ( ; it.current(); ++it)
599 it.current()->setOpen(
609 enableButton(User1,
true);
610 enableButton(User2,
true);
611 newCB->setEnabled(
true);
612 noTreeCB->setEnabled(
true);
613 subCB->setEnabled(
true);
616 TQListViewItemIterator it(groupView);
617 for ( ; it.current(); ++it)
620 setOriginalParent( it.current()->parent() );
630 (item->listView() == groupView &&
634 arrowBtn1->setEnabled(
false);
635 arrowBtn2->setEnabled(
false);
639 TQListView* currentView = item->listView();
640 if (currentView == groupView)
642 setDirectionButton1(Right);
643 setDirectionButton2(Right);
644 if (
static_cast<GroupItem*
>(item)->isOn())
647 arrowBtn1->setEnabled(
false);
648 arrowBtn2->setEnabled(
true);
651 arrowBtn1->setEnabled(
true);
652 arrowBtn2->setEnabled(
false);
654 }
else if (currentView == subView)
657 setDirectionButton1(Left);
659 arrowBtn1->setEnabled(
true);
660 arrowBtn2->setEnabled(
false);
661 }
else if (currentView == unsubView)
664 setDirectionButton2(Left);
666 arrowBtn1->setEnabled(
false);
667 arrowBtn2->setEnabled(
true);
674 if (mDirButton1 == Right)
676 if (groupView->currentItem() &&
685 if (subView->currentItem())
701 void KSubscription::slotButton2()
703 if (mDirButton2 == Right)
705 if (groupView->currentItem() &&
714 if (unsubView->currentItem())
732 if (!noTreeCB->isChecked() && !newCB->isChecked() && !subCB->isChecked())
745 if (mLastText.isEmpty())
748 if (!mLastText.isEmpty() && text.length() < mLastText.length())
752 TQListViewItemIterator it(groupView);
753 for ( ; it.current(); ++it)
755 it.current()->setVisible(
true);
756 it.current()->setEnabled(
true);
774 text = i18n(
"Loading... (1 matching)",
"Loading... (%n matching)",
777 text = i18n(
"%1: (1 matching)",
"%1: (%n matching)",
activeItemCount())
780 leftLabel->setText(text);
786 enableButton(User1,
false);
793 #include "ksubscription.moc"
A class representing a single group item (what's that?)
bool isCheckItem() const
Get if this is a checkable item.
virtual void setDescription()
Sets the description from the KGroupInfo Reimplement this for special cases.
virtual void setOn(bool on)
Reimplemented Sets the subscribed property (only while items are loaded)
virtual void stateChange(bool on)
Reimlemented Calls KSubscription::changeItemState if mIgnoreStateChange == false.
virtual int width(const TQFontMetrics &, const TQListView *, int column) const
Reimplemented Calls TQListViewItem or TQCheckListItem.
virtual void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align)
Reimplemented Calls TQListViewItem or TQCheckListItem.
KGroupInfo info()
Get/Set the KGroupInfo.
void setVisible(bool b)
Reimplemented Sets items invisible or disabled or even moves them.
virtual void setup()
Reimplemented Calls TQListViewItem or TQCheckListItem.
bool lastOpenState()
Get/Set the last open state.
virtual void paintFocus(TQPainter *, const TQColorGroup &cg, const TQRect &r)
Reimplemented Calls TQListViewItem or TQCheckListItem.
This class provides a generic subscription widget The dialog itself has a main listview that holds al...
TQListViewItem * getListItem(TQListView *view, const KGroupInfo &gi)
Gets the item from the listview Returns 0 if the item can't be found.
void restoreOriginalParent()
Moves all items from toplevel back to their original position.
void slotLoadFolders()
The reload-button is pressed.
bool isLoading()
Returns true if items are being constructed Call 'slotLoadingComplete' to switch this.
void slotLoadingComplete()
Call this slot when you have created all items.
void slotUpdateStatusLabel()
Updates the status-label.
KAccount * account()
Get/Set the account.
void slotCBToggled()
Slot for the checkboxes.
void slotChangeButtonState(TQListViewItem *)
Changes the current state of the buttons.
void slotButton1()
Buttons are clicked.
void removeListItem(TQListView *view, const KGroupInfo &gi)
Removes the item from the listview.
void changeItemState(GroupItem *item, bool on)
Makes all changes after an item is toggled called by the item's stateChange-method.
void filterChanged(TQListViewItem *item=0, const TQString &text=TQString())
Update the item-states (visible, enabled) when a filter criteria changed.
void saveOpenStates()
Saves the open states.
void setStartItem(const KGroupInfo &info)
The item that should be selected on startup.
void listChanged()
Emitted when the amount of items in the groupView changes (e.g.
void slotFilterTextChanged(const TQString &text)
Filter text changed.
bool itemInListView(TQListView *view, const KGroupInfo &gi)
Is the item in the given listview.
uint activeItemCount()
The amount of items that are visible and enabled.
void restoreOpenStates()
Restores the saved open state.
This file defines a generic subscription widget and some support classes.