File: modulebrowser_impl.cpp

package info (click to toggle)
korelib 0.0.1-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,788 kB
  • ctags: 1,918
  • sloc: sh: 8,555; cpp: 3,989; makefile: 633; ansic: 65
file content (155 lines) | stat: -rw-r--r-- 4,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

#include <qapp.h>
#include <qbutton.h>
#include <qpushbutton.h>
#include <qbuttongroup.h>
#include <qheader.h>
#include <qstring.h>

#include <kore/version.h>
#include <kore/kernel.h>
#include <kore/modulemanager.h>
#include <kore/servicemanager.h>

#include "modulebrowser_impl.h"
#include "moduleview_impl.h"

using namespace kore;

ModuleBrowserImpl::ModuleListItem::ModuleListItem( QListView* parent, Module* mod): QListViewItem( parent )
{
    _module = mod;
    const Module::Info* nfo = mod->info();
    QString addr;
    addr.sprintf("0x%08x", mod);
    int cols = parent->columns();
    for(int i=0; i<cols; i++)
    {
        QString colName = parent->columnText( i );
        QString txt;
        if( colName == "ID" )
            txt = addr;
        else if ( colName == "Name" )
            txt = nfo->name();
        else if ( colName == "Type" )
            txt = nfo->type();
        else if ( colName == "Version" )
            txt = (const char*) (*nfo->version());
        else if ( colName == "API Version" )
            txt = (const char*) (*nfo->APIVersion());
        else if ( colName == "Description" )
            txt = nfo->description();
        setText(i, txt);
    }
}

/*
 *  Constructs a ModuleBrowserImpl which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'
 */
ModuleBrowserImpl::ModuleBrowserImpl( QWidget* parent,  const char* name, WFlags fl )
    : ModuleBrowserWidget( parent, name, fl )
{
    slotRefreshModuleList();
}

/*
 *  Destroys the object and frees any allocated resources
 */
ModuleBrowserImpl::~ModuleBrowserImpl()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 * protected slot
 */
void ModuleBrowserImpl::slotClose()
{
    QApplication::exit(0);
}
/*
 * protected slot
 */
void ModuleBrowserImpl::slotRefreshColumns(int id)
{
    QButton* btn = showColumns->find(id);
    QString columnName(btn->text());
    columnName.remove(0,1);
    if( btn->isOn() )
    {
        moduleListView->addColumn( columnName );
        slotRefreshModuleList();
    }
    else
    {
        int column;
        for(column = 0; column < moduleListView->columns() ; column++)
            if( moduleListView->columnText( column ) == columnName )
                break;
        moduleListView->removeColumn(column);
    }
}
/*
 * protected slot
 */
void ModuleBrowserImpl::slotRefreshModuleList()
{
    ModuleManager* mm = dynamic_cast<ModuleManager*> (Kernel::instance()->serviceManager()->registeredProvider("Kore/Kernel/Module Manager"));
    if( !mm ) // ouch! No ModuleManager found...
        return;
    Module** modules = mm->registeredModules();
    moduleListView->clear();
    for(int i=0; modules[i]; i++)
        (void) new ModuleListItem( moduleListView, modules[i] );
    delete[] modules;
}
/*
 * protected slot
 */
void ModuleBrowserImpl::slotSelectionChanged()
{
    bool noSelection = true;
    for( QListViewItem* item = moduleListView->firstChild(); item; item = item->nextSibling() )
        if( moduleListView->isSelected( item ) )
        {
            noSelection = false;
            break;
        }
    if( noSelection )
    {
        unregisterButton->setEnabled(false);
        propertiesButton->setEnabled(false);
    }
    else
    {
        unregisterButton->setEnabled(true);
        propertiesButton->setEnabled(true);
    }
}
/*
 * protected slot
 */
void ModuleBrowserImpl::slotShowModuleProperties()
{
    ModuleManager* mm = dynamic_cast<ModuleManager*> (Kernel::instance()->serviceManager()->registeredProvider("Kore/Kernel/Module Manager"));
    if( !mm ) // ouch! No ModuleManager found...
        return;
    for( QListViewItem* item = moduleListView->firstChild(); item; item = item->nextSibling() )
        if( moduleListView->isSelected( item ) )
            (new ModuleViewImpl( dynamic_cast<ModuleListItem*>(item)->module(), this ))->show();
    slotRefreshModuleList();
}
/*
 * protected slot
 */
void ModuleBrowserImpl::slotUnregisterModules()
{
    ModuleManager* mm = dynamic_cast<ModuleManager*> (Kernel::instance()->serviceManager()->registeredProvider("Kore/Kernel/Module Manager"));
    if( !mm ) // ouch! No ModuleManager found...
        return;
    for( QListViewItem* item = moduleListView->firstChild(); item; item = item->nextSibling() )
        if( moduleListView->isSelected( item ) )
            mm->unregisterModule( dynamic_cast<ModuleListItem*>(item)->module() );
    slotRefreshModuleList();
}