00001 #include "nntpgroups.h"
00002
00003 #include <libmailwrapper/settings.h>
00004 #include <opie2/odebug.h>
00005 #include <qlistview.h>
00006 #include <qlineedit.h>
00007
00008 using namespace Opie::Core;
00009
00010 NNTPGroups::NNTPGroups(NNTPaccount *account, QWidget* parent, const char* name, WFlags fl)
00011 : NNTPGroupsUI(parent,name,fl),subscribedGroups()
00012 {
00013 m_Account = account;
00014 fillGroups();
00015 }
00016
00017 NNTPGroups::~NNTPGroups()
00018 {
00019
00020 }
00021
00022 void NNTPGroups::slotGetNG()
00023 {
00024 if (!m_Account) return;
00025 GroupListView->clear();
00026 NNTPwrapper tmp( m_Account );
00027 QString filter = Groupfilteredit->text();
00028 QStringList list = tmp.listAllNewsgroups(filter);
00029 subscribedGroupsNotListed = subscribedGroups;
00030 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00031 QCheckListItem *item;
00032 item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox );
00033 if ( subscribedGroups.contains( (*it) ) >= 1 ) {
00034 item->setOn( true );
00035 subscribedGroupsNotListed.remove((*it));
00036 }
00037 }
00038 }
00039
00040 void NNTPGroups::fillGroups()
00041 {
00042 if (!m_Account) return;
00043 subscribedGroups = m_Account->getGroups();
00044 for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) {
00045 QCheckListItem *item;
00046 item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox );
00047 item->setOn( true );
00048 }
00049 }
00050
00051 void NNTPGroups::storeValues()
00052 {
00053 if (!m_Account) return;
00054 QListViewItemIterator list_it( GroupListView );
00055 subscribedGroups.clear();
00056 for ( ; list_it.current(); ++list_it ) {
00057 if ( ( (QCheckListItem*)list_it.current() )->isOn() ) {
00058 odebug << list_it.current()->text(0) << oendl;
00059 subscribedGroups.append( list_it.current()->text(0) );
00060 }
00061 }
00062 subscribedGroups+=subscribedGroupsNotListed;
00063 m_Account->setGroups( subscribedGroups );
00064 }