summaryrefslogtreecommitdiffstats
path: root/adept/libadept/groupeddesktopselector.cpp
blob: 07875b7e33a1878d293b3bdfd7e772b896c50fed (plain)
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
/** -*- C++ -*-
    @file adept/groupeddestkopselector.cpp
    @author Peter Rockai <me@mornfall.net>
*/

#include <tqobjectlist.h>
#include <tqvbox.h>
#include <tqlabel.h>
#include <tqtimer.h>
#include <kiconloader.h>
#include <tdeglobal.h>
#include <kseparator.h>
#include <tdeapplication.h>

#include <apt-front/cache/component/desktop.h>
#include <adept/groupeddesktopselector.h>
#include <adept/desktoplist.h>
#include <adept/utils.h>

using namespace aptFront;
using namespace cache;

namespace adept {

GroupedDesktopSelector::GroupedDesktopSelector( TQWidget *p, const char *n )
    : KJanusWidget( p, n, IconList ), m_policy( 0 )
{
    observeComponent< cache::component::Packages >();
    m_pages.push_back( addPage( TQString( "Initializing..." ) ) );
    TQObjectList *chld = queryList( TQWIDGET_OBJECT_NAME_STRING );
    TQObjectListIt it( *chld ); TQWidget *o;
    while ((o = dynamic_cast< TQWidget * >( it.current() )) != 0) {
        if ( dynamic_cast< TQLabel * >( o ) != 0 )
            o->hide();
        if ( dynamic_cast< KSeparator * >( o ) != 0 )
            o->hide();
        ++it;
    } // *hack*
    
    // AAAA hack
    TQLayoutIterator li = layout()->iterator();
    TQHBoxLayout *hbox = 0;
    while ( li.current() != 0 ) {
        hbox = dynamic_cast< TQHBoxLayout * >( li.current() );
        if ( hbox ) break;
        ++li;
    }
    kdDebug() << "hacking hbox = " << hbox << endl;
    if ( hbox ) {
        li = hbox->iterator();
        while ( li.current() != 0 ) {
            TQSpacerItem *spacer = dynamic_cast< TQSpacerItem * >( li.current() );
            if ( spacer ) {
                hbox->removeItem( spacer );
                delete spacer;
            }
            ++li;
        }
    }
}

void GroupedDesktopSelector::notifyPreRebuild( component::Base * ) {
    clear();
}

void GroupedDesktopSelector::notifyPostRebuild( component::Base * ) {
    // TQTimer::singleShot( 0, this, TQT_SLOT( fill() ) );
}

void GroupedDesktopSelector::clear()
{
    if ( !m_pages.empty() )
        showPage( m_pages.front() );
    while ( !m_pages.empty() ) {
        removePage( m_pages.back() );
        delete m_pages.back();
        m_pages.pop_back();
    }
}

void GroupedDesktopSelector::fill()
{
    component::Desktop &d = cache::Global::get().component< component::Desktop >();
    fill( d.entries() );
}

void GroupedDesktopSelector::fill( component::Desktop::EntityRange r )
{
    component::Desktop &d = cache::Global::get().component< component::Desktop >();
    utils::Range< std::string > gr;
    TQString last = pageTitle( activePageIndex() );

    clear();

    bool shown = false;

    for ( gr = d.availableGroups( r ); gr != gr.end(); gr.advance() ) {

        component::Desktop::EntityRange cr = d.group( *gr );
        TQString name = u8( *gr );
        std::cerr << "group for " << cr->name() << ": " << r->group() << std::endl;
        name = ( name != u8( "" ) ? name : u8( "Legacy" ) );

        TQPixmap icon( TDEGlobal::iconLoader()->iconPath(
                          policy() ? policy()->iconForGroup( name ) : u8( "" ), -32 ) );

        TQVBox *b = addVBoxPage( name, name, icon );
        m_pages.push_back( b );
        std::cerr << "creating list for " << *gr << std::endl;

        DesktopList *l = new DesktopList( b );
        l->setTitle( name );
        connect( l, TQT_SIGNAL( request( cache::entity::Package,
                                     cache::component::State::Action ) ),
                 this, TQT_SIGNAL( request( cache::entity::Package,
                                        cache::component::State::Action ) ) );
        connect( l, TQT_SIGNAL( showDescription( cache::entity::Desktop ) ),
                 this, TQT_SIGNAL( showDescription( cache::entity::Desktop ) ) );

        l->insertRange( intersectionRange( r, cr ) );
        // l->insertRange( cr );

        std::cerr << "created list for " << *gr << std::endl;
        if ( name == last ) {
            showPage( b );
            shown = true;
        }
        kapp->processEvents();
    }

    if ( m_pages.empty() )
        m_pages.push_back( addPage( TQString( "No Results" ) ) );
    if ( !shown )
        showPage( pageIndex( m_pages.front() ) );
}

}