Author: dmacvicar
Date: Mon Dec 15 18:35:06 2008
New Revision: 54149
URL: http://svn.opensuse.org/viewcvs/yast?rev=54149&view=rev
Log:
Finally I got somewhere. I can display the icons already
Starting from Thomas control center was much more productive than trying
to plug my models into the old code.
Categories in progress. but backup
Added:
branches/tmp/tgoettlicher/yast2cc_rewrite/src/models_test.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.h
Modified:
branches/tmp/tgoettlicher/yast2cc_rewrite/CMakeLists.txt
branches/tmp/tgoettlicher/yast2cc_rewrite/src/CMakeLists.txt
branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/CMakeLists.txt?rev=54149&r1=54148&r2=54149&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/CMakeLists.txt (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/CMakeLists.txt Mon Dec 15 18:35:06 2008
@@ -1,5 +1,5 @@
PROJECT( yast2-control-center )
-CMAKE_MINIMUM_REQUIRED( VERSION 2.4.0 )
+CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )
FIND_PACKAGE( Qt4 REQUIRED )
SET( RPMNAME "yast2-control-center" )
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/CMakeLists.txt?rev=54149&r1=54148&r2=54149&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/CMakeLists.txt (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/CMakeLists.txt Mon Dec 15 18:35:06 2008
@@ -2,19 +2,30 @@
INCLUDE_DIRECTORIES(/usr/include/initng ${CMAKE_CURRENT_BINARY_DIR})
+SET(THEMEDIR "/usr/share/YaST2/theme")
+
+ADD_DEFINITIONS("-DLOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/share/YaST2/locale\"")
+ADD_DEFINITIONS("-DICON_DIR=\"${THEMEDIR}/current/icons/32x32/apps\"")
+ADD_DEFINITIONS("-DPIXMAP_DIR=\"${THEMEDIR}/current/icons/32x32/apps\"")
+ADD_DEFINITIONS("-DDESKTOP_TRANSLATIONS_DIR=\"${CMAKE_INSTALL_PREFIX}/share/locale\"")
+ADD_DEFINITIONS("-DMODULES_DESKTOP_DIR=\"${CMAKE_INSTALL_PREFIX}/share/applications/YaST2\"")
+ADD_DEFINITIONS("-DGROUPS_DESKTOP_DIR=\"${CMAKE_INSTALL_PREFIX}/share/applications/YaST2/groups\"")
+
SET(yast2-control-center_SRCS
main.cpp
main_window.cpp
-
-kcategorizedview.cpp
-menuitem.cpp
-kcategorydrawer.cpp
-kcategorizedsortfilterproxymodel.cpp
-kcmodulemodel.cpp
-moduleiconitem.cpp
-kcmoduleinfo.cpp
-
-
+ kcategorizedview.cpp
+ menuitem.cpp
+ kcategorydrawer.cpp
+ kcategorizedsortfilterproxymodel.cpp
+ kcmodulemodel.cpp
+ moduleiconitem.cpp
+ kcmoduleinfo.cpp
+
+ yqdesktopfilesmodel.cpp
+ yqmodulegroupsmodel.cpp
+ yqmodulesmodel.cpp
+ yqmodulesproxymodel.cpp
)
#SET(yast2-control-center_UIS
@@ -23,32 +34,43 @@
SET(yast2-control-center_HDRS
main_window.h
-kcategorizedview.h
-menuitem.h
-kcmodulemodel.h
-kcategorydrawer.h
-kcategorizedsortfilterproxymodel.h
-moduleiconitem.h
-kcmoduleinfo.h
-kcategorizedview_p.h
+ kcategorizedview.h
+ menuitem.h
+ kcmodulemodel.h
+ kcategorydrawer.h
+ kcategorizedsortfilterproxymodel.h
+ moduleiconitem.h
+ kcmoduleinfo.h
+ kcategorizedview_p.h
+
+ yqdesktopfilesmodel.h
+ yqmodulegroupsmodel.h
+ yqmodulesmodel.h
+ yqmodulesproxymodel.h
)
#SET(yast2-control-center_RCCS ../files.qrc)
QT4_AUTOMOC(${yast2-control-center_SRCS})
-
# QT4_WRAP_UI(yast2-control-center_UIS_H ${yast2-control-center_UIS})
-
QT4_WRAP_CPP(yast2-control-center_MOC ${yast2-control-center_UIS_H})
-
QT4_ADD_RESOURCES(yast2-control-center_RCC_SRCS ${yast2-control-center_RCCS})
#ADD_DEFINITIONS(-DQT_NO_DEBUG)
ADD_EXECUTABLE(yast2-control-center ${yast2-control-center_SRCS} ${yast2-control-center_MOC} ${yast2-control-center_RCC_SRCS})
-
TARGET_LINK_LIBRARIES(yast2-control-center ${QT_LIBRARIES})
-
INSTALL(TARGETS yast2-control-center DESTINATION bin)
+
+
+SET(MODELS_TEST_SRCS
+ models_test.cpp
+ yqdesktopfilesmodel.cpp
+ yqmodulegroupsmodel.cpp
+ yqmodulesmodel.cpp )
+
+QT4_AUTOMOC(${MODELS_TEST_SRCS})
+ADD_EXECUTABLE(models_test ${MODELS_TEST_SRCS})
+TARGET_LINK_LIBRARIES(models_test ${QT_QTCORE_LIBRARIES} ${QT_QTGUI_LIBRARIES})
\ No newline at end of file
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp?rev=54149&r1=54148&r2=54149&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp Mon Dec 15 18:35:06 2008
@@ -1,71 +1,58 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
#include "main_window.h"
#include <QLayout>
#include <QLabel>
+#include <QDebug>
-
-
+#include "kcategorizedsortfilterproxymodel.h"
#include "kcategorizedview.h"
-#include "menuitem.h"
-#include "kcmodulemodel.h"
#include "kcategorydrawer.h"
+#include "yqmodulesproxymodel.h"
+#include "yqmodulesmodel.h"
+
#include "moduleiconitem.h"
-#include <iostream>
MainWindow::MainWindow() : QMainWindow()
{
+ qDebug();
- std::cout << "MainWindow::MainWindow()" << std::endl;
-
- QWidget *centralWidget = new QWidget;
- setCentralWidget(centralWidget);
- QHBoxLayout *layout = new QHBoxLayout;
- centralWidget->setLayout(layout);
-
-
- MenuItem *rootItem = new MenuItem(true, 0);
-
- readMenu( rootItem );
-
+ QWidget *centralWidget = new QWidget(this);
+ setCentralWidget(centralWidget);
+ QHBoxLayout *layout = new QHBoxLayout;
+ centralWidget->setLayout(layout);
-
-
-
-
- KCModuleModel *model;
-
-
- foreach ( MenuItem* item, rootItem->children ) {
- model = new KCModuleModel( item, this );
- KCategoryDrawer * drawer = new KCategoryDrawer;
- KCategorizedView * tv = new KCategorizedView( this );
- tv->setSelectionMode(QAbstractItemView::SingleSelection);
+ KCategoryDrawer * drawer = new KCategoryDrawer;
+ KCategorizedView * tv = new KCategorizedView( this );
+
+ layout->addWidget(tv);
+
+ tv->setSelectionMode(QAbstractItemView::SingleSelection);
// tv->setSpacing(KDialog::spacingHint());
- tv->setCategoryDrawer( drawer );
- tv->setViewMode( QListView::IconMode );
- tv->setItemDelegate( new ModuleIconItemDelegate( this ) );
- tv->setMouseTracking( true );
- tv->viewport()->setAttribute( Qt::WA_Hover );
- KCategorizedSortFilterProxyModel * kcsfpm = new SystemSettingsProxyModel( this );
- kcsfpm->setCategorizedModel( true );
- kcsfpm->setSourceModel( model );
- kcsfpm->setFilterRole( KCModuleModel::UserFilterRole );
- kcsfpm->setFilterCaseSensitivity( Qt::CaseInsensitive );
- kcsfpm->sort( 0 );
- tv->setModel( kcsfpm );
-// tv->setModel( model );
-
-
-
- layout->addWidget(tv);
-}
-
-
-
-
-
-
+ tv->setCategoryDrawer( drawer );
+ tv->setViewMode( QListView::IconMode );
+ tv->setItemDelegate( new ModuleIconItemDelegate( this ) );
+ tv->setMouseTracking( true );
+ tv->viewport()->setAttribute( Qt::WA_Hover );
+ YQModulesModel *model = new YQModulesModel(this);
+ KCategorizedSortFilterProxyModel * kcsfpm = new YQModulesProxyModel( this );
+ kcsfpm->setCategorizedModel( true );
+ kcsfpm->setSourceModel( model );
+ //kcsfpm->setFilterRole( KCModuleModel::UserFilterRole );
+ //kcsfpm->setFilterCaseSensitivity( Qt::CaseInsensitive );
+ kcsfpm->sort( 0 );
+ tv->setModel( kcsfpm );
}
@@ -73,75 +60,4 @@
{
}
-
-
-void MainWindow::readMenu( MenuItem * parent )
-{
-
- int depth=0;
- MenuItem * current = parent;
-
-// for cats
-
- MenuItem * menuItem = new MenuItem(true, parent);
- menuItem->name = "Kat1";
-
-// readMenu
- MenuItem* infoItem = new MenuItem(false,menuItem);
- infoItem->name="Kat1";
-
-/*
-
-
-
-
- // look for any categories inside this level, and recurse into them
- int depth = 0;
- MenuItem * current = parent;
- while ( current && current->parent ) {
- depth++;
- current = current->parent;
- }
-
- QString space;
- space.fill( ' ', depth * 2 );
- std::cout << space.data() << "Looking for children in '" << parent->name.data() << "'";
- for (int i = 0; i < categories.size(); ++i) {
- KService::Ptr entry = categories.at(i);
- QString parentCategory = entry->property("X-KDE-System-Settings-Parent-Category").toString();
- QString category = entry->property("X-KDE-System-Settings-Category").toString();
- std::cout << "Examining category " << parentCategory.data() << "/" << category.data();
- if ( parentCategory == parent->name ) {
- KCModuleInfo module( entry->entryPath() );
-
- MenuItem * menuItem = new MenuItem(true, parent);
- menuItem->name = category;
- menuItem->service = entry;
- menuItem->item = module;
- readMenu( menuItem );
- }
- }
-
- // scan for any modules at this level and add them
- for (int i = 0; i < modules.size(); ++i) {
- KService::Ptr entry = modules.at(i);
- QString category = entry->property("X-KDE-System-Settings-Parent-Category").toString();
- //kDebug() << "Examining module " << category;
- if(!parent->name.isEmpty() && category == parent->name ) {
- kDebug() << space << "found module '" << entry->name() << "' " << entry->desktopEntryPath();
- // Add the module info to the menu
- KCModuleInfo module(entry->entryPath());
- kDebug() << space << "filename is " << module.fileName();
- //append(module);
- MenuItem * infoItem = new MenuItem(false, parent);
- infoItem->name = category;
- infoItem->service = entry;
- infoItem->item = module;
- }
- }
-
-*/
-}
-
-
#include "main_window.moc"
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h?rev=54149&r1=54148&r2=54149&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h Mon Dec 15 18:35:06 2008
@@ -1,15 +1,29 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "kcategorizedview.h"
-#include "menuitem.h"
-#include "kcmodulemodel.h"
#include "kcategorydrawer.h"
#include "moduleiconitem.h"
#include <QMainWindow>
+/**
+ * Main window of the control center
+ *
+ * @author Thomas Goettlicher
+ */
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -19,10 +33,6 @@
~MainWindow();
public slots:
-
-private:
- void readMenu( MenuItem * parent );
-
};
#endif
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/models_test.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/models_test.cpp?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/models_test.cpp (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/models_test.cpp Mon Dec 15 18:35:06 2008
@@ -0,0 +1,34 @@
+#include <QApplication>
+#include <QListView>
+
+#include "yqdesktopfilesmodel.h"
+#include "yqmodulesmodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QListView window;
+ YQDesktopFilesModel model("/usr/share/applications/YaST2/groups", &window);
+ model.addIconPath("/usr/share/YaST2/theme/current/icons/32x32/apps");
+
+ window.setModel(&model);
+ window.show();
+
+ //QListView window2;
+ //YQDesktopFilesModel model2("/usr/share/applications/YaST2", &window2);
+ //model2.addIconPath("/usr/share/YaST2/theme/current/icons/32x32/apps");
+ //model2.addIconPath("/usr/share/icons/hicolor/32x32/apps");
+
+ //window2.setModel(&model2);
+ //window2.show();
+
+ QListView window3;
+ YQModulesModel model3(&window3);
+
+ window3.setModel(&model3);
+ window3.show();
+
+
+ return app.exec();
+}
+
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp Mon Dec 15 18:35:06 2008
@@ -0,0 +1,246 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#include <QDebug>
+#include <QSettings>
+#include <QDir>
+#include <QIcon>
+#include <QHash>
+#include <QFileSystemWatcher>
+
+#include "yqdesktopfilesmodel.h"
+
+// private data of the model
+class YQDesktopFilesModel::Private
+{
+public:
+ Private()
+ {}
+
+ ~Private()
+ {}
+
+ // directories to read
+ QStringList desktop_dirs;
+
+ QStringList icon_dirs;
+
+ // list of .desktop files read from disk
+ QStringList desktop_files;
+ // already read data
+ // row -> ( key -> data )
+ QHash > cache;
+ QFileSystemWatcher watcher;
+};
+
+
+YQDesktopFilesModel::YQDesktopFilesModel( const QString &dir, QObject * parent )
+ : QAbstractItemModel(parent)
+ , d(new Private)
+{
+ connect(&d->watcher, SIGNAL(directoryChanged(const QString &)),
+ SLOT(slotDesktopFilesDirectoryChanged( const QString & ) ) );
+
+ addDesktopFilesPath(dir);
+ readDesktopFilesDirectories();
+}
+
+YQDesktopFilesModel::~YQDesktopFilesModel()
+{
+ delete d;
+}
+
+QModelIndex YQDesktopFilesModel::indexForValue( const QString &key, const QVariant &value )
+{
+ return QModelIndex();
+}
+
+void YQDesktopFilesModel::addDesktopFilesPath( const QString &dir )
+{
+ d->desktop_dirs << dir;
+ d->watcher.addPath(dir);
+ readDesktopFilesDirectories();
+}
+
+void YQDesktopFilesModel::addIconPath( const QString &dir )
+{
+ d->icon_dirs << dir;
+}
+
+void YQDesktopFilesModel::slotDesktopFilesDirectoryChanged( const QString &path )
+{
+ //emit dataChanged();
+ reset();
+}
+
+void YQDesktopFilesModel::readDesktopFilesDirectories()
+{
+ //d->desktop_dirs.clear();
+ d->desktop_files.clear();
+ d->cache.clear();
+
+ QStringListIterator dirs(d->desktop_dirs);
+
+ while ( dirs.hasNext() )
+ {
+ // read group desktop files
+ QDir dir( dirs.next() + "/", "*.desktop" );
+
+ if ( ! dir.exists() )
+ {
+ qWarning() << "Directory " << dir.absolutePath() << " does not exist";
+ }
+ else
+ {
+ QStringListIterator desktop_files(dir.entryList());
+ while ( desktop_files.hasNext() )
+ {
+ QString desktop_file = desktop_files.next();
+ d->desktop_files << ( dir.absolutePath() + "/" + desktop_file );
+ }
+
+ }
+ qDebug() << d->desktop_files.size() << " groups";
+ }
+}
+
+int YQDesktopFilesModel::columnCount( const QModelIndex & parent ) const
+{
+ return 1;
+}
+
+int YQDesktopFilesModel::rowCount( const QModelIndex & parent ) const
+{
+ return d->desktop_files.size();
+}
+
+QModelIndex YQDesktopFilesModel::index( int row, int column, const QModelIndex & parent ) const
+{
+ return createIndex(row, column);
+}
+
+/**
+ * read a YaST group .desktop file
+ */
+QHash readDesktopFile( const QString &filename )
+{
+ // desktop file data
+ QHash data;
+
+ QSettings desktopFile( filename, QSettings::IniFormat );
+
+ // check if parsing was correct
+ if ( desktopFile.status() != QSettings::NoError )
+ {
+ qWarning() << "Error reading desktop file " << filename;
+ return data;
+ }
+
+ desktopFile.beginGroup( "Desktop Entry" );
+
+ QStringList keys(desktopFile.allKeys());
+ QStringListIterator keyit(keys);
+ while (keyit.hasNext())
+ {
+ QString key(keyit.next());
+ data.insert(key, desktopFile.value(key));
+ }
+
+
+ return data;
+}
+
+
+QVariant YQDesktopFilesModel::data( const QModelIndex &index, int role ) const
+{
+
+ QStringListIterator it(d->desktop_files);
+
+ int count = 0;
+ while ( it.hasNext() )
+ {
+ QString filename = it.next();
+ if ( count == index.row() )
+ {
+ // first lookup in cache
+ QHash data;
+ if ( d->cache.contains(index.row()) )
+ {
+ data = d->cache.value(index.row());
+ }
+ else
+ {
+ data = readDesktopFile(filename);
+
+ if ( data.empty() )
+ return QVariant();
+ d->cache.insert(index.row(), data);
+ }
+
+ // check the role and column
+ if ( role == Qt::DisplayRole )
+ {
+ return data.value("Name");
+ }
+ else if ( role == Qt::DecorationRole )
+ {
+ QString icon = data.value("Icon").toString();
+ QRegExp extension( "\\.(png|jpg)$", Qt::CaseInsensitive );
+ if ( icon.indexOf( extension ) < 0 ) // no .png or .jpg extension?
+ icon += ".png"; // assume .png
+ QStringListIterator it(d->icon_dirs);
+ while (it.hasNext())
+ {
+ QString icondir(it.next());
+ if ( QFile::exists(icondir + "/" + icon) )
+ {
+ return QIcon(icondir + "/" + icon);
+ }
+ }
+ return QVariant();
+ }
+ else if ( role == Qt::UserRole )
+ {
+ // user role has app specific data
+ switch ( index.column() )
+ {
+ case Name:
+ return data.value("Name");
+ case Group:
+ return data.value("X-SuSE-YaST-Group");
+ case Icon:
+ return data.value("Icon");
+ case SortKey:
+ return data.value("X-SuSE-YaST-SortKey");
+ default:
+ return QVariant();
+ }
+ }
+ else
+ {
+ return QVariant();
+ }
+ }
+ else
+ {
+ count++;
+ }
+ }
+
+ return QVariant();
+}
+
+QModelIndex YQDesktopFilesModel::parent( const QModelIndex & index ) const
+{
+ return QModelIndex();
+}
+
+#include "yqdesktopfilesmodel.moc"
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h Mon Dec 15 18:35:06 2008
@@ -0,0 +1,76 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef YQDESKTOPFILESMODEL_H
+#define YQDESKTOPFILESMODEL_H
+
+#include <QAbstractItemModel>
+#include <QStringList>
+
+/**
+ * this class represents a directory with .desktop files
+ * Each row is a desktop file, and each column, its
+ * attributes.
+ *
+ * @author Duncan Mac-Vicar P.
+ */
+class YQDesktopFilesModel : public QAbstractItemModel
+{
+Q_OBJECT
+
+public:
+ enum Columns
+ {
+ Name,
+ Group,
+ Icon,
+ SortKey,
+ ColumnCount
+ };
+
+ YQDesktopFilesModel( const QString &dir, QObject * parent = 0 );
+ ~YQDesktopFilesModel();
+
+ /**
+ * Add a directory where Desktop files will be searched
+ */
+ void addDesktopFilesPath( const QString &dir );
+
+ /**
+ * Add a directory where to look for icons
+ */
+ void addIconPath( const QString &dir );
+
+ // reimplemented methods from QAbstractItemModel
+
+ virtual int columnCount( const QModelIndex & parent ) const;
+ virtual int rowCount( const QModelIndex & parent ) const;
+
+ virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
+
+ /**
+ * returns the index of the first item for which the key has
+ * the provided value
+ */
+ QModelIndex indexForValue( const QString &key, const QVariant &value );
+
+ virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
+ virtual QModelIndex parent( const QModelIndex & index ) const;
+protected:
+ void readDesktopFilesDirectories();
+ protected slots:
+ void slotDesktopFilesDirectoryChanged( const QString &path );
+private:
+ class Private;
+ Private *const d;
+};
+
+#endif
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp Mon Dec 15 18:35:06 2008
@@ -0,0 +1,41 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#include <QDebug>
+#include <QSettings>
+#include <QDir>
+#include <QIcon>
+#include <QHash>
+
+#include "yqmodulegroupsmodel.h"
+
+#define DEFAULT_GROUP_ICON "yast-default-group.png"
+
+YQModuleGroupsModel::YQModuleGroupsModel( QObject * parent )
+ : YQDesktopFilesModel( GROUPS_DESKTOP_DIR, parent)
+{
+}
+
+YQModuleGroupsModel::~YQModuleGroupsModel()
+{
+}
+
+QModelIndex YQModuleGroupsModel::indexForGroupId( const QString &groupid ) const
+{
+ return QModelIndex();
+}
+
+QVariant YQModuleGroupsModel::data( const QModelIndex &index, int role ) const
+{
+ return YQDesktopFilesModel::data(index, role);
+}
+
+#include "yqmodulegroupsmodel.moc"
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h Mon Dec 15 18:35:06 2008
@@ -0,0 +1,51 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef YQMODULEGROUPSMODEL_H
+#define YQMODULEGROUPSMODEL_H
+
+#include <QStringList>
+#include "yqdesktopfilesmodel.h"
+
+/**
+ * this class represents YaST module groups
+ * so they can be used in any GUI item
+ *
+ * @author Duncan Mac-Vicar P.
+ */
+class YQModuleGroupsModel : public YQDesktopFilesModel
+{
+Q_OBJECT
+public:
+
+ enum UserRoleData
+ {
+ RawName,
+ SortKey,
+ Hidden,
+ LastColumn
+ };
+
+ YQModuleGroupsModel( QObject * parent = 0 );
+ ~YQModuleGroupsModel();
+
+ virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
+
+ /**
+ * Returns the model index from an id (like "Virtualization")
+ *
+ * Useful if you need to get data, and you don't know the index but only
+ * the group id, which you may had obtain in the modules model for example.
+ */
+ QModelIndex indexForGroupId( const QString &groupid ) const;
+};
+
+#endif
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp Mon Dec 15 18:35:06 2008
@@ -0,0 +1,58 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#include "yqmodulesmodel.h"
+#include "yqmodulesproxymodel.h"
+
+#include "yqmodulegroupsmodel.h"
+
+class YQModulesModel::Private
+{
+public:
+ Private()
+ {}
+ ~Private()
+ {}
+ YQModuleGroupsModel groupsModel;
+};
+
+
+
+YQModulesModel::YQModulesModel( QObject * parent )
+ : YQDesktopFilesModel( MODULES_DESKTOP_DIR, parent)
+ , d(new Private)
+{
+ addIconPath("/usr/share/YaST2/theme/current/icons/32x32/apps");
+ addIconPath("/usr/share/icons/hicolor/32x32/apps");
+}
+
+YQModulesModel::~YQModulesModel()
+{
+}
+
+QVariant YQModulesModel::data( const QModelIndex &index, int role ) const
+{
+ if ( role == KCategorizedSortFilterProxyModel::CategoryDisplayRole )
+ {
+ return QVariant("Foo");
+
+ }
+ else if ( role == KCategorizedSortFilterProxyModel::CategorySortRole )
+ {
+ return QVariant(32);
+ }
+ else
+ {
+ return YQDesktopFilesModel::data(index, role);
+ }
+}
+
+#include "yqmodulesmodel.moc"
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h Mon Dec 15 18:35:06 2008
@@ -0,0 +1,46 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef YQMODULESMODEL_H
+#define YQMODULESMODEL_H
+
+#include <QStringList>
+#include "yqdesktopfilesmodel.h"
+
+/**
+ * this class represents YaST module groups
+ * so they can be used in any GUI item
+ *
+ * @author Duncan Mac-Vicar P.
+ */
+class YQModulesModel : public YQDesktopFilesModel
+{
+Q_OBJECT
+public:
+
+ enum UserRoleData
+ {
+ RawName,
+ SortKey,
+ Hidden,
+ LastColumn
+ };
+
+ YQModulesModel( QObject * parent = 0 );
+ ~YQModulesModel();
+
+ virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
+private:
+ class Private;
+ Private *const d;
+};
+
+#endif
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.cpp?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.cpp (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.cpp Mon Dec 15 18:35:06 2008
@@ -0,0 +1,34 @@
+
+#include "yqmodulesproxymodel.h"
+
+YQModulesProxyModel::YQModulesProxyModel( QObject * parent )
+ : KCategorizedSortFilterProxyModel(parent)
+{
+}
+
+YQModulesProxyModel::~YQModulesProxyModel()
+{
+}
+
+bool YQModulesProxyModel::subSortLessThan(const QModelIndex &left, const QModelIndex &right) const
+{
+ return KCategorizedSortFilterProxyModel::subSortLessThan(left, right);
+}
+
+int YQModulesProxyModel::compareCategories(const QModelIndex &left, const QModelIndex &right) const
+{
+ return KCategorizedSortFilterProxyModel::compareCategories(left, right);
+}
+
+
+
+// QVariant YQModulesProxyModel::data( const QModelIndex &index, int role ) const
+// {
+// if ( role == CategoryDisplayRole )
+// {
+// }
+
+// return YQDesktopFilesModel::data(index, role);
+// }
+
+#include "yqmodulesproxymodel.moc"
Added: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.h?rev=54149&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.h (added)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesproxymodel.h Mon Dec 15 18:35:06 2008
@@ -0,0 +1,55 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ _____ _____ |
+| \ \ / / / ___|_ _| |
+| \ V /__ _\ `--. | | |
+| \ // _` |`--. \ | | |
+| | | (_| /\__/ / | | |
+| \_/\__,_\____/ \_/ |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef YQMODULESPROXYMODEL_H
+#define YQMODULESPROXYMODEL_H
+
+#include <QStringList>
+#include "kcategorizedsortfilterproxymodel.h"
+
+/**
+ * Proxy Model to sort by categories
+ *
+ * @author Duncan Mac-Vicar P.
+ */
+class YQModulesProxyModel : public KCategorizedSortFilterProxyModel
+{
+Q_OBJECT
+public:
+
+ YQModulesProxyModel( QObject * parent = 0 );
+ ~YQModulesProxyModel();
+
+ /**
+ * This method has a similar purpose as lessThan() has on QSortFilterProxyModel.
+ * It is used for sorting items that are in the same category.
+ *
+ * @return Returns true if the item @p left is less than the item @p right when sorting.
+ */
+ virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
+
+ /**
+ * This method compares the category of the @p left index with the category
+ * of the @p right index.
+ *
+ * Internally and if not reimplemented, this method will ask for @p left and
+ * @p right models for role CategorySortRole. In order to correctly sort
+ * categories, the data() metod of the model should return a qlonglong (or numeric) value, or
+ * a QString object. QString objects will be sorted with QString::localeAwareCompare if
+ * sortCategoriesByNaturalComparison() is true.
+ *
+ */
+ virtual int compareCategories(const QModelIndex &left, const QModelIndex &right) const;
+
+ //virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
+};
+
+#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org