Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / kngrouppropdlg.cpp
blob01d0d322744678abee77c9928de8c75a9d204aad
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #include "kngrouppropdlg.h"
17 #include "configuration/identity_widget.h"
18 #include "knconfigmanager.h"
19 #include "knconfigwidgets.h"
20 #include "knglobals.h"
21 #include "kngroup.h"
22 #include "utilities.h"
23 #include "utils/locale.h"
25 #include <QGroupBox>
26 #include <QLabel>
27 #include <QCheckBox>
28 #include <QVBoxLayout>
29 #include <QGridLayout>
30 #include <QComboBox>
32 #include <KCharsets>
33 #include <klocale.h>
34 #include <klineedit.h>
35 #include <kvbox.h>
39 KNGroupPropDlg::KNGroupPropDlg( KNGroup *group, QWidget *parent )
40 : KPageDialog( parent ),
41 g_rp(group), n_ickChanged(false)
43 setFaceType( Tabbed );
44 setCaption( i18nc( "@title:window %1=newsgroup name", "Properties of %1", group->groupname() ) );
45 setButtons( Ok|Cancel|Help );
46 setDefaultButton( Ok );
48 // General tab ===============================================
50 QWidget *page = new QWidget( this );
51 addPage( page, i18nc( "@title:tab", "General" ) );
52 QVBoxLayout *pageL = new QVBoxLayout(page);
53 pageL->setSpacing(3);
55 // settings
56 QGroupBox *gb = new QGroupBox( i18nc( "@title:group", "Settings"), page );
57 pageL->addWidget(gb);
58 QGridLayout *grpL=new QGridLayout(gb);
59 grpL->setSpacing(5);
60 grpL->setMargin(15);
62 grpL->addItem( new QSpacerItem( 0, fontMetrics().lineSpacing()-9), 0, 0 );
64 n_ick=new KLineEdit(gb);
65 if (g_rp->hasName())
66 n_ick->setText(g_rp->name());
67 QLabel *l = new QLabel( i18nc( "@label:textbox Alternative name of a newsgroup", "Nickname:" ), gb );
68 l->setBuddy(n_ick);
69 grpL->addWidget(l,1,0);
70 grpL->addWidget(n_ick,1,1, 1,2);
72 u_seCharset = new QCheckBox( i18nc( "@label:listbox", "Use different default charset:" ), gb );
73 u_seCharset->setChecked(g_rp->useCharset());
74 grpL->addWidget(u_seCharset,2,0, 1, 2 );
76 c_harset=new QComboBox(gb);
77 c_harset->setEditable(false);
78 c_harset->addItems( KNode::Utilities::Locale::encodings() );
79 QString defaultCsDesc = KGlobal::charsets()->descriptionForEncoding( QString::fromAscii( g_rp->defaultCharset() ) );
80 c_harset->setCurrentIndex( c_harset->findText( defaultCsDesc ) );
81 c_harset->setEnabled(g_rp->useCharset());
82 connect(u_seCharset, SIGNAL(toggled(bool)), c_harset, SLOT(setEnabled(bool)));
83 grpL->addWidget(c_harset, 2,2);
85 grpL->setColumnStretch(1,1);
86 grpL->setColumnStretch(2,2);
88 // group name & description
89 gb = new QGroupBox( i18nc( "@title:group", "Description" ), page );
90 pageL->addWidget(gb);
91 grpL=new QGridLayout(gb);
92 grpL->setSpacing(5);
93 grpL->setMargin(15);
95 grpL->addItem( new QSpacerItem( 0, fontMetrics().lineSpacing()-9), 0, 0 );
97 l = new QLabel( i18nc( "@label name of a newsgroup", "Name:" ), gb );
98 grpL->addWidget(l,1,0);
99 l=new QLabel(group->groupname(),gb);
100 grpL->addWidget(l,1,2);
102 l = new QLabel( i18nc( "@label description of a newsgroup", "Description:" ), gb );
103 grpL->addWidget(l,2,0);
104 l=new QLabel(g_rp->description(),gb);
105 grpL->addWidget(l,2,2);
107 l = new QLabel( i18nc( "@label status of posting to a newsgroup", "Status:" ), gb );
108 grpL->addWidget(l,3,0);
109 QString status;
110 switch (g_rp->status()) {
111 case KNGroup::unknown: status = i18nc( "posting status", "unknown" );
112 break;
113 case KNGroup::readOnly: status=i18n("posting forbidden");
114 break;
115 case KNGroup::postingAllowed: status=i18n("posting allowed");
116 break;
117 case KNGroup::moderated: status = i18nc( "posting status", "moderated" );
118 break;
120 l=new QLabel(status,gb);
121 grpL->addWidget(l,3,2);
123 grpL->addItem( new QSpacerItem(20, 0 ), 0, 1 );
124 grpL->setColumnStretch(2,1);
126 // statistics
127 gb = new QGroupBox( i18nc( "@title:group", "Statistics" ), page );
128 pageL->addWidget(gb);
129 grpL=new QGridLayout(gb);
130 grpL->setSpacing(5);
131 grpL->setMargin(15);
133 grpL->addItem( new QSpacerItem( 0, fontMetrics().lineSpacing()-9), 0, 0 );
135 l=new QLabel(i18n("Articles:"), gb);
136 grpL->addWidget(l,1,0);
137 l=new QLabel(QString::number(g_rp->count()),gb);
138 grpL->addWidget(l,1,2);
140 l=new QLabel(i18n("Unread articles:"), gb);
141 grpL->addWidget(l,2,0);
142 l=new QLabel(QString::number(g_rp->count()-g_rp->readCount()),gb);
143 grpL->addWidget(l,2,2);
145 l=new QLabel(i18n("New articles:"), gb);
146 grpL->addWidget(l,3,0);
147 l=new QLabel(QString::number(g_rp->newCount()),gb);
148 grpL->addWidget(l,3,2);
150 l=new QLabel(i18n("Threads with unread articles:"), gb);
151 grpL->addWidget(l,4,0);
152 l=new QLabel(QString::number(g_rp->statThrWithUnread()),gb);
153 grpL->addWidget(l,4,2);
155 l=new QLabel(i18n("Threads with new articles:"), gb);
156 grpL->addWidget(l,5,0);
157 l=new QLabel(QString::number(g_rp->statThrWithNew()),gb);
158 grpL->addWidget(l,5,2);
160 grpL->addItem( new QSpacerItem(20, 0 ), 0, 1 );
161 grpL->setColumnStretch(2,1);
163 pageL->addStretch(1);
165 // Specific Identity tab =========================================
166 i_dWidget = new KNode::IdentityWidget( g_rp, knGlobals.componentData(), this );
167 addPage( i_dWidget, i18nc( "@title:tab", "Identity" ) );
169 // per server cleanup configuration
170 mCleanupWidget = new KNode::GroupCleanupWidget( g_rp->cleanupConfig(), this );
171 addPage( mCleanupWidget, i18nc( "@title:tab", "Cleanup" ) );
172 mCleanupWidget->load();
174 KNHelper::restoreWindowSize("groupPropDLG", this, sizeHint());
175 connect(this,SIGNAL(okClicked()),SLOT(slotOk()));
180 KNGroupPropDlg::~KNGroupPropDlg()
182 KNHelper::saveWindowSize("groupPropDLG", size());
187 void KNGroupPropDlg::slotOk()
189 if( !(g_rp->name()==n_ick->text()) ) {
190 g_rp->setName(n_ick->text());
191 n_ickChanged=true;
194 i_dWidget->save();
195 mCleanupWidget->save();
197 g_rp->setUseCharset(u_seCharset->isChecked());
198 g_rp->setDefaultCharset( KGlobal::charsets()->encodingForName( c_harset->currentText() ).toLatin1() );
200 accept();