KDevelop API Documentation

filegroupsconfigwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001-2002 by Bernd Gehrmann                             *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "filegroupsconfigwidget.h"
00013 
00014 #include <qlistview.h>
00015 #include <knotifyclient.h>
00016 #include <klocale.h>
00017 
00018 #include "domutil.h"
00019 #include "addfilegroupdlg.h"
00020 #include "filegroupspart.h"
00021 
00022 
00023 FileGroupsConfigWidget::FileGroupsConfigWidget(FileGroupsPart *part,
00024                                                QWidget *parent, const char *name)
00025     : FileGroupsConfigWidgetBase(parent, name)
00026 {
00027     m_part = part;
00028 
00029     listview->setSorting(-1);
00030     
00031     readConfig();
00032 }
00033 
00034 
00035 FileGroupsConfigWidget::~FileGroupsConfigWidget()
00036 {}
00037 
00038 
00039 void FileGroupsConfigWidget::readConfig()
00040 {
00041     QDomDocument &dom = *m_part->projectDom();
00042     DomUtil::PairList list = DomUtil::readPairListEntry(dom, "/kdevfileview/groups",
00043                                                         "group", "name", "pattern");
00044 
00045     QListViewItem *lastItem = 0;
00046 
00047     DomUtil::PairList::ConstIterator it;
00048     for (it = list.begin(); it != list.end(); ++it) {
00049         QListViewItem *newItem = new QListViewItem(listview, (*it).first, (*it).second);
00050         if (lastItem)
00051             newItem->moveItem(lastItem);
00052         lastItem = newItem;
00053     }
00054 }
00055 
00056 
00057 void FileGroupsConfigWidget::storeConfig()
00058 {
00059     DomUtil::PairList list;
00060     
00061     QListViewItem *item = listview->firstChild();
00062     while (item) {
00063         list << DomUtil::Pair(item->text(0), item->text(1));
00064         item = item->nextSibling();
00065     }
00066 
00067     DomUtil::writePairListEntry(*m_part->projectDom(), "/kdevfileview/groups",
00068                                 "group", "name", "pattern", list);
00069 }
00070 
00071 
00072 void FileGroupsConfigWidget::addGroup()
00073 {
00074     AddFileGroupDialog dlg;
00075     dlg.setCaption(i18n("Add File Group"));
00076     if (!dlg.exec())
00077         return;
00078 
00079     (void) new QListViewItem(listview, dlg.title(), dlg.pattern());
00080 }
00081 
00082 
00083 void FileGroupsConfigWidget::editGroup()
00084 {
00085     if (listview->childCount()==0 || listview->currentItem()==0)
00086         return;
00087     AddFileGroupDialog dlg(listview->currentItem()->text(0),listview->currentItem()->text(1));
00088     dlg.setCaption(i18n("Edit File Group"));
00089     if (!dlg.exec() || dlg.title().isEmpty() || dlg.pattern().isEmpty())
00090         return;
00091     listview->currentItem()->setText(0,dlg.title());
00092     listview->currentItem()->setText(1,dlg.pattern());
00093 }
00094 
00095 
00096 void FileGroupsConfigWidget::removeGroup()
00097 {
00098     delete listview->currentItem();
00099 }
00100 
00101 
00102 void FileGroupsConfigWidget::moveUp()
00103 {
00104     if (listview->currentItem() == listview->firstChild()) {
00105         KNotifyClient::beep();
00106         return;
00107     }
00108 
00109     QListViewItem *item = listview->firstChild();
00110     while (item->nextSibling() != listview->currentItem())
00111         item = item->nextSibling();
00112     item->moveItem(listview->currentItem());
00113 }
00114 
00115 
00116 void FileGroupsConfigWidget::moveDown()
00117 {
00118    if (listview->currentItem()->nextSibling() == 0) {
00119         KNotifyClient::beep();
00120         return;
00121    }
00122 
00123    listview->currentItem()->moveItem(listview->currentItem()->nextSibling());
00124 }
00125 
00126 
00127 void FileGroupsConfigWidget::accept()
00128 {
00129     storeConfig();
00130     m_part->refresh();
00131 }
00132 
00133 #include "filegroupsconfigwidget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:57 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003