Source Code (Use browser search to find items of interest.)
Class Index
kppp'AccountingSelector (./kdenetwork/kppp/acctselect.h:47)
class AccountingSelector : public KCheckGroupBox {
Q_OBJECT
public:
AccountingSelector(QWidget *parent = 0, bool _isnewaccount = false, const char *name = 0);
~AccountingSelector() {}
bool save();
private:
QListViewItem *findByName(QString name);
void setupTreeWidget();
void insertDir(QDir, QListViewItem * = 0);
QString fileNameToName(QString);
QString nameToFileName(QString);
private slots:
void enableItems(bool);
void slotSelectionChanged(QListViewItem* i);
private:
QListView *tl;
QComboBox *use_vol;
QPixmap pmfolder, pmfile;
QLabel *selected;
QListViewItem *edit_item;
QString edit_s;
bool isnewaccount;
};
kppp'AccountingSelector::AccountingSelector() (./kdenetwork/kppp/acctselect.cpp:55)
AccountingSelector::AccountingSelector(QWidget *parent, bool _isnewaccount, const char *name)
: KCheckGroupBox(i18n("Enable accounting"), parent, name),
isnewaccount(_isnewaccount)
{
QVBoxLayout *l1 = new QVBoxLayout(peer(), 10, 10);
connect(this, SIGNAL(toggled(bool)), this, SLOT(enableItems(bool)));
// insert the tree widget
tl = new QListView(peer(), "treewidget");
connect(tl, SIGNAL(selectionChanged(QListViewItem*)), this,
SLOT(slotSelectionChanged(QListViewItem*)));
tl->setMinimumSize(220, 200);
l1->addWidget(tl, 1);
// label to display the currently selected ruleset
QHBoxLayout *l11 = new QHBoxLayout;
l1->addSpacing(10);
l1->addLayout(l11);
QLabel *lsel = new QLabel(i18n("Selected:"), peer());
selected = new QLabel(peer());
selected->setFrameStyle(QFrame::Sunken | QFrame::WinPanel);
selected->setLineWidth(1);
selected->setFixedHeight(selected->sizeHint().height() + 16);
l11->addWidget(lsel, 0);
l11->addSpacing(10);
l11->addWidget(selected, 1);
// volume accounting
l1->addStretch(1);
QHBoxLayout *l12 = new QHBoxLayout;
l1->addLayout(l12);
QLabel *usevol_l = new QLabel(i18n("Volume accounting:"), peer());
use_vol = new QComboBox(peer());
use_vol->insertItem(i18n("No accounting"), 0);
use_vol->insertItem(i18n("Bytes in"), 1);
use_vol->insertItem(i18n("Bytes out"), 2);
use_vol->insertItem(i18n("Bytes in and out"), 3);
use_vol->setCurrentItem(gpppdata.VolAcctEnabled());
l12->addWidget(usevol_l);
l12->addWidget(use_vol);
// load the pmfolder pixmap from KDEdir
pmfolder = UserIcon("folder");
// scale the pixmap
if(pmfolder.width() > 0) {
QWMatrix wm;
wm.scale(16.0/pmfolder.width(), 16.0/pmfolder.width());
pmfolder = pmfolder.xForm(wm);
}
// load the pmfolder pixmap from KDEdir
pmfile = UserIcon("phone");
// scale the pixmap
if(pmfile.width() > 0) {
QWMatrix wm;
wm.scale(16.0/pmfile.width(), 16.0/pmfile.width());
pmfile = pmfile.xForm(wm);
}
setChecked(gpppdata.AcctEnabled());
setChecked(true);
setupTreeWidget();
l1->activate();
}
kppp'AccountingSelector::fileNameToName() (./kdenetwork/kppp/acctselect.cpp:127)
QString AccountingSelector::fileNameToName(QString s) {
s.replace(QRegExp("_"), " ");
return s;
}
kppp'AccountingSelector::nameToFileName() (./kdenetwork/kppp/acctselect.cpp:135)
QString AccountingSelector::nameToFileName(QString s) {
s.replace(QRegExp(" "), "_");
return s;
}
kppp'AccountingSelector::findByName() (./kdenetwork/kppp/acctselect.cpp:142)
QListViewItem *AccountingSelector::findByName(QString name)
{
QListViewItem *ch = tl->firstChild();
while(ch) {
if(ch->text(0) == name)
return ch;
ch = ch->nextSibling();
}
return 0;
}
kppp'AccountingSelector::insertDir() (./kdenetwork/kppp/acctselect.cpp:154)
void AccountingSelector::insertDir(QDir d, QListViewItem *root) {
QListViewItem* tli = 0;
// sanity check
if(!d.exists() || !d.isReadable())
return;
// set up filter
d.setNameFilter("*.rst");
d.setFilter(QDir::Files);
d.setSorting(QDir::Name);
// read the list of files
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
// traverse the list and insert into the widget
while((fi = it.current())) {
++it;
QString samename = fi->fileName();
QListViewItem *i = findByName(samename);
// skip this file if already in tree
if(i)
continue;
// check if this is the file we should mark
QString name = fileNameToName(fi->baseName());
if(root)
tli = new QListViewItem(root, name);
else
tli = new QListViewItem(tl, name);
tli->setPixmap(0, pmfile);
// check if this is the item we are searching for
// (only in "Edit"-mode, not in "New"-mode
if(!isnewaccount &&
(edit_s == QString(fi->filePath()).right(edit_s.length()))) {
edit_item = tli;
}
}
// set up a filter for the directories
d.setFilter(QDir::Dirs);
d.setNameFilter("*");
const QFileInfoList *dlist = d.entryInfoList();
QFileInfoListIterator dit(*dlist);
while((fi = dit.current())) {
// skip "." and ".." directories
if(fi->fileName().left(1) != ".") {
// convert to human-readable name
QString name = fileNameToName(fi->fileName());
// if the tree already has an item with this name,
// skip creation and use this one, otherwise
// create a new entry
QListViewItem *i = findByName(name);
if(!i) {
QListViewItem* item;
if(root)
item = new QListViewItem(root, name);
else
item = new QListViewItem(tl, name);
item->setPixmap(0, pmfolder);
insertDir(QDir(fi->filePath()), item);
} else
insertDir(QDir(fi->filePath()), i);
}
++dit;
}
}
kppp'AccountingSelector::setupTreeWidget() (./kdenetwork/kppp/acctselect.cpp:237)
void AccountingSelector::setupTreeWidget() {
// search the item
edit_item = 0;
if(!isnewaccount) {
edit_s = gpppdata.accountingFile();
}
else
edit_s = "";
tl->addColumn( i18n("Available rules") );
tl->setColumnWidth(0, 205);
tl->setRootIsDecorated(true);
// look in ~/.kde/share/apps/kppp/Rules and $KDEDIR/share/apps/kppp/Rules
QStringList dirs = KGlobal::dirs()->resourceDirs("appdata");
for (QStringList::ConstIterator it = dirs.begin();
it != dirs.end(); it++) {
insertDir(QDir((*it) + "Rules"), 0);
}
// when mode is "Edit", then hightlight the
// appropriate item
if(!isnewaccount && edit_item) {
tl->setSelected(edit_item, true);
tl->setOpen(edit_item->parent(), true);
tl->ensureItemVisible(edit_item);
}
enableItems(isChecked());
}
kppp'AccountingSelector::enableItems() (./kdenetwork/kppp/acctselect.cpp:269)
void AccountingSelector::enableItems(bool enabled) {
tl->setEnabled(enabled);
if(!enabled || (!tl->currentItem()))
selected->setText(i18n("(none)"));
else {
QListViewItem* i = tl->currentItem();
QString s;
while(i) {
s = "/" + i->text(0) + s;
i = i->parent();
}
selected->setText(s.mid(1));
s += ".rst";
edit_s = nameToFileName(s);
}
}
kppp'AccountingSelector::slotSelectionChanged() (./kdenetwork/kppp/acctselect.cpp:290)
void AccountingSelector::slotSelectionChanged(QListViewItem* i) {
if(!i || i->childCount())
return;
if(!isChecked())
return;
enableItems(true);
}
kppp'AccountingSelector::save() (./kdenetwork/kppp/acctselect.cpp:302)
bool AccountingSelector::save() {
if(isChecked()) {
gpppdata.setAccountingFile(edit_s);
gpppdata.setAcctEnabled(true);
} else {
gpppdata.setAccountingFile("");
gpppdata.setAcctEnabled(false);
}
gpppdata.setVolAcctEnabled(use_vol->currentItem());
return true;
}