summaryrefslogtreecommitdiffstats
path: root/kicker/menuext/tom/tom.cc
blob: 80ea3e71d39cee8613e32a38e560a167dd9ae936 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
/* This file is part of the KDE project
   Copyright (C) 2003 Aaron J. Seigo <aseigo@olympusproject.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <iostream>
using namespace std;

#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>

#include <qdir.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qregexp.h>
#include <qsettings.h>
#include <qstyle.h>
#include <qfile.h>

#include <dcopclient.h>
#include <kapplication.h>
#include <kcombobox.h>
#include <kdialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kiconeffect.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimetype.h>
#include <kpixmap.h>
#include <krecentdocument.h>
#include <kservice.h>
#include <kservicegroup.h>
#include <kstandarddirs.h>
#include <kstdaction.h>
#include <ksycocaentry.h>

#include "menuinfo.h"
#include "service_mnu.h"
#include "kicker.h"
#include "tom.h"

const int configureMenuID = 1000;
const int contextMenuTitleID = 10000;
const int destMenuTitleID = 10001;

extern "C"
{
    KDE_EXPORT void* init_kickermenu_tom()
    {
        KGlobal::locale()->insertCatalogue("libkickermenu_tom");
        return new TOMFactory;
    }
};

TOMFactory::TOMFactory(QObject *parent, const char *name)
: KLibFactory(parent, name)
{
}

QObject* TOMFactory::createObject(QObject *parent, const char *name, const char*, const QStringList&)
{
    return new TOM((QWidget*)parent, name);
}

#include <qmenudata.h>
/*
 * TODO: switch the backgroundmode when translucency turns on/off
 * TODO: catch font changes too?
 */
class runMenuWidget : public QWidget, public QMenuItem
{
    public:
        runMenuWidget(KPopupMenu* parent, int index)
            : QWidget (parent),
              m_menu(parent),
              m_index(index)
        {
            setFocusPolicy(StrongFocus);

            QHBoxLayout* runLayout = new QHBoxLayout(this);
            textRect = fontMetrics().boundingRect(i18n("Run:"));
            runLayout->setSpacing(KDialog::spacingHint());
            runLayout->addSpacing((KDialog::spacingHint() * 3) + KIcon::SizeMedium + textRect.width());
            icon = DesktopIcon("run", KIcon::SizeMedium);
            /*QLabel* l1 = new QLabel(this);
            QPixmap foo = DesktopIcon("run", KIcon::SizeMedium);
            cout << "foo is: " << foo.width() << " by " << foo.height() << endl;
            l1->setPixmap(foo);
            runLayout->addWidget(l1);*/
            /*QLabel* l2 = new QLabel(i18n("&Run: "), this);
            l2->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
            l2->setBuddy(this);
            runLayout->addWidget(l2);*/
            m_runEdit = new KHistoryCombo(this);
            m_runEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
            runLayout->addWidget(m_runEdit, 10);
            runLayout->addSpacing(KDialog::spacingHint());

            QSettings settings;
            if (settings.readEntry("/KStyle/Settings/MenuTransparencyEngine", "Disabled") != "Disabled")
            {
                setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
                //l1->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
                //l2->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
                m_runEdit->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
            }
            else
            {
                /*setBackgroundMode(Qt::NoBackground, Qt::NoBackground);
                l1->setBackgroundMode(Qt::NoBackground, Qt::NoBackground);
                l2->setBackgroundMode(Qt::NoBackground, Qt::NoBackground);
                m_runEdit->setBackgroundMode(Qt::NoBackground, Qt::NoBackground);*/
                //l1->setAutoMask(true);
                //l1->setBackgroundMode(Qt::NoBackground, Qt::NoBackground);
                //l2->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
                //m_runEdit->setBackgroundMode(Qt::X11ParentRelative, Qt::X11ParentRelative);
            }

            setMinimumHeight(KIcon::SizeMedium + 2);
        }
        ~runMenuWidget() {}


        void paintEvent(QPaintEvent * /*e*/)
        {
            QPainter p(this);
            QRect r(rect());
            // ew, nasty hack. may result in coredumps due to horrid C-style cast???
            kapp->style().drawControl(QStyle::CE_PopupMenuItem, &p, m_menu, r, palette().active(), QStyle::Style_Enabled,
                                      QStyleOption(static_cast<QMenuItem*>(this), 0, KIcon::SizeMedium ));
            p.drawPixmap(KDialog::spacingHint(), 1, icon);
            p.drawText((KDialog::spacingHint() * 2) + KIcon::SizeMedium, textRect.height() + ((height() - textRect.height()) / 2), i18n("Run:"));
        }

        void focusInEvent (QFocusEvent* e)
        {
            if (!e || e->gotFocus())
            {
                m_menu->setActiveItem(m_index);
                m_runEdit->setFocus();
            }
        }

        void enterEvent(QEvent*)
        {
            focusInEvent(0);
        }

    private:
        KPopupMenu* m_menu;
        KHistoryCombo* m_runEdit;
        QPixmap icon;
        QRect textRect;
        int m_index;
};

TOM::TOM(QWidget *parent, const char *name)
    : KPanelMenu(parent, name),
      m_maxIndex(0)
{
    disableAutoClear();
    m_submenus.setAutoDelete(true);
    setCaption(i18n("Task-Oriented Menu"));

    // KMenu legacy: support some menu config options
    KConfig* config = KGlobal::config();
    config->setGroup("menus");
    m_detailedTaskEntries = config->readBoolEntry("DetailedMenuEntries", false);
    if (m_detailedTaskEntries)
    {
        m_detailedNamesFirst = config->readBoolEntry("DetailedEntriesNamesFirst", false);
    }

    m_isImmutable = Kicker::kicker()->isImmutable() || config->groupIsImmutable("TOM");
    config->setGroup("TOM");
    m_largerFont = font();
    m_largerFont = config->readFontEntry("Font", &m_largerFont);
}

TOM::~TOM()
{
    slotClear();
}

void TOM::initializeRecentApps(QPopupMenu* menu)
{
    /*
     * TODO: make this real
     *       add a KDE-wide "commands run" registry
     */

    if (!m_isImmutable)
    {
        menu->insertSeparator();
        menu->insertItem(i18n("Configure This Menu"), configureMenuID);
    }
}

void TOM::initializeRecentDocs()
{
    m_recentDocsMenu->clear();
    m_recentDocsMenu->insertItem(SmallIconSet("history_clear"), i18n("Clear History"),
                                 this, SLOT(clearRecentDocHistory()));
    m_recentDocsMenu->insertSeparator();

    m_recentDocURLs = KRecentDocument::recentDocuments();

    if (m_recentDocURLs.isEmpty())
    {
        setItemEnabled(m_recentDocsMenu->insertItem(i18n("No Entries")), false);
        return;
    }

    int id = 0;
    for (QStringList::ConstIterator it = m_recentDocURLs.begin();
         it != m_recentDocURLs.end();
         ++it)
    {
        /*
         * TODO: make the number of visible items configurable?
         */

        KDesktopFile f(*it, true /* read only */);
        m_recentDocsMenu->insertItem(DesktopIcon(f.readIcon(), KIcon::SizeMedium),
                                     f.readName().replace('&', "&&"), id);
        ++id;
    }
}

int TOM::appendTaskGroup(KConfig& config, bool inSubMenu)
{
    if (!config.hasGroup("General"))
    {
        return 0;
    }

    config.setGroup("General");

    if (config.readBoolEntry("Hidden", false))
    {
        return 0;
    }

    QString name = config.readEntry("Name", i18n("Unknown"));
    QString icon = config.readEntry("Icon");
    int numTasks = config.readNumEntry("NumTasks", 0);

    if (numTasks < 1)
    {
        return 0;
    }

    KPopupMenu* taskGroup;
    if( inSubMenu )
    {
        taskGroup = new KPopupMenu(this);

        if (icon != QString::null)
        {
            insertItem(DesktopIcon(icon, KIcon::SizeMedium), name, taskGroup);
        }
        else
        {
            insertItem(name, taskGroup);
        }
    }
    else
    {
        taskGroup = this;
    }

    int foundTasks = 0;
    for (int i = 0; i < numTasks; ++i)
    {
        QString groupName = QString("Task%1").arg(i);

        if (config.hasGroup(groupName))
        {
            config.setGroup(groupName);

            if (config.readBoolEntry("Hidden", false))
            {
                continue;
            }

            QString name = config.readEntry("Name");
            // in case the name contains an ampersand, double 'em up
            name.replace("&", "&&");
            QString desktopfile = config.readPathEntry("DesktopFile");
            KService::Ptr pService = KService::serviceByDesktopPath(desktopfile);

            if (!pService)
            {
                pService = KService::serviceByDesktopName(desktopfile);

                if (!pService)
                {
                    continue;
                }
            }

            QString execName = pService->name();
            QString icon = pService->icon();

            if (m_detailedTaskEntries && !execName.isEmpty())
            {
                QString tmp = i18n("%1 (%2)");

                if (m_detailedNamesFirst)
                {
                    name = tmp.arg(execName).arg(name);
                }
                else
                {
                    name = tmp.arg(name).arg(execName);
                }
            }

            ++m_maxIndex;
            if (icon.isEmpty())
            {
                taskGroup->insertItem(name, m_maxIndex);
            }
            else
            {
       
		QIconSet iconset = BarIconSet(icon, 22);
		if (iconset.isNull())
		    taskGroup->insertItem(name, m_maxIndex);
		else
		    taskGroup->insertItem(iconset, name, m_maxIndex);
	
            }

            m_tasks.insert(m_maxIndex, pService);
            ++foundTasks;
        }
    }

    // if we end up with an empty task group, get rid of the menu
    if (foundTasks == 0)
    {
        if (inSubMenu)
        {
            delete taskGroup;
        }

        return 0;
    }

    connect(taskGroup, SIGNAL(activated(int)), this, SLOT(runTask(int)));
    // so we have an actual task group menu with tasks, let's add it

    if (inSubMenu)
    {
        QObject::connect(taskGroup, SIGNAL(aboutToShowContextMenu(KPopupMenu*, int, QPopupMenu*)),
                         this, SLOT(contextualizeRMBmenu(KPopupMenu*, int, QPopupMenu*)));

        m_submenus.append(taskGroup);

        taskGroup->setFont(m_largerFont);
        taskGroup->setKeyboardShortcutsEnabled(true);

        if (!m_isImmutable && !config.isImmutable())
        {
            taskGroup->insertSeparator();
            taskGroup->insertItem("Modify These Tasks", configureMenuID);
            QPopupMenu* rmbMenu = taskGroup->contextMenu();
            rmbMenu->setFont(m_largerFont);
            KPopupTitle* title = new KPopupTitle();
            title->setText(i18n("%1 Menu Editor").arg(name));
            rmbMenu->insertItem(title, contextMenuTitleID);
            rmbMenu->insertItem(i18n("Add This Task to Panel"));
            rmbMenu->insertItem(i18n("Modify This Task..."));
            rmbMenu->insertItem(i18n("Remove This Task..."), this, SLOT(removeTask()));
            rmbMenu->insertItem(i18n("Insert New Task..."));
        }
    }

    return foundTasks;
}
/*
 * TODO: track configuration file changes.
void TOM::configChanged()
{
    KPanelMenu::configChanged();
    setInitialized(false);
    initialize();
}
*/
void TOM::initialize()
{
    if (initialized())
    {
        return;
    }

    setInitialized(true);
    m_submenus.clear();
    m_tasks.clear();
    clear();

    /* hack to make items larger. should use something better?
    m_largerFont = font();
    if (m_largerFont.pointSize() < 18)
    {
        m_largerFont.setPointSize(18);
    }
    setFont(m_largerFont);*/


    /*if (!loadSidePixmap())
    {
      m_sidePixmap = m_sideTilePixmap = QPixmap();
    }
    else
    {
      connect(kapp, SIGNAL(kdisplayPaletteChanged()), SLOT(paletteChanged()));
    }*/

    // TASKS
    insertTitle(i18n("Tasks"), contextMenuTitleID);

    QStringList dirs = KGlobal::dirs()->findDirs("data", "kicker/tom/");
    QStringList::ConstIterator dIt = dirs.begin();
    QStringList::ConstIterator dEnd = dirs.end();

    for (; dIt != dEnd; ++dIt )
    {
        QDir dir(*dIt);

        QStringList entries = dir.entryList("*rc", QDir::Files);
        QStringList::ConstIterator eIt = entries.begin();
        QStringList::ConstIterator eEnd = entries.end();

        for (; eIt != eEnd; ++eIt )
        {
            KConfig config(*dIt + *eIt);
            appendTaskGroup(config);
        }
    }

    PanelServiceMenu* moreApps = new PanelServiceMenu(QString::null, QString::null, this, "More Applications");
    moreApps->setFont(m_largerFont);
    insertItem(DesktopIcon("misc", KIcon::SizeMedium), i18n("More Applications"), moreApps);
    m_submenus.append(moreApps);

    if (!m_isImmutable)
    {
        insertSeparator();
        // TODO: connect to taskgroup edits
        insertItem("Modify The Above Tasks");
    }

    // DESTINATIONS
    insertTitle(i18n("Destinations"), destMenuTitleID);
    int numDests = 0;
    QString destinationsConfig = locate("appdata", "tom/destinations");

    if (!destinationsConfig.isEmpty() && QFile::exists(destinationsConfig))
    {
        KConfig config(destinationsConfig);
        numDests = appendTaskGroup(config, false);
    }

    if (numDests == 0)
    {
        removeItem(destMenuTitleID);
    }
    else if (kapp->authorize("run_command"))
    {
        insertItem(DesktopIcon("run", KIcon::SizeMedium), i18n("Run Command..."), this, SLOT(runCommand()));
    }

    // RECENTLY USED ITEMS
    insertTitle(i18n("Recently Used Items"), contextMenuTitleID);

    m_recentDocsMenu = new KPopupMenu(this, "recentDocs");
    m_recentDocsMenu->setFont(m_largerFont);
    connect(m_recentDocsMenu, SIGNAL(aboutToShow()), this, SLOT(initializeRecentDocs()));
    connect(m_recentDocsMenu, SIGNAL(activated(int)), this, SLOT(openRecentDocument(int)));
    insertItem(DesktopIcon("document", KIcon::SizeMedium), i18n("Recent Documents"), m_recentDocsMenu);
    m_submenus.append(m_recentDocsMenu);

    KPopupMenu* recentApps = new KPopupMenu(this, "recentApps");
    recentApps->setFont(m_largerFont);
    recentApps->setKeyboardShortcutsEnabled(true);
    initializeRecentApps(recentApps);
    insertItem(i18n("Recent Applications"), recentApps);
    m_submenus.append(recentApps);

    // SPECIAL ITEMS
    insertTitle(i18n("Special Items"), contextMenuTitleID);

    // if we have no destinations, put the run command here
    if (numDests == 0 && kapp->authorize("run_command"))
    {
        insertItem(DesktopIcon("run", KIcon::SizeMedium), i18n("Run Command..."), this, SLOT(runCommand()));
    }


    KConfig* config = KGlobal::config();
    QStringList menu_ext = config->readListEntry("Extensions");
    if (!menu_ext.isEmpty())
    {
        bool needSeparator = false;
        for (QStringList::ConstIterator it = menu_ext.begin(); it != menu_ext.end(); ++it)
        {
            MenuInfo info(*it);
            if (!info.isValid())
            {
                continue;
            }

            KPanelMenu *menu = info.load();
            if (menu)
            {
                ++m_maxIndex;
                insertItem(DesktopIcon(info.icon(), KIcon::SizeMedium), info.name(), menu, m_maxIndex);
                m_submenus.append(menu);
                needSeparator = true;
            }
        }

        if (needSeparator)
        {
            insertSeparator();
        }
    }


    QString username;
    struct passwd *userInfo = getpwuid(getuid());
    if (userInfo)
    {
        username = QString::fromLocal8Bit(userInfo->pw_gecos);
        if (username.find(',') != -1)
        {
            // Remove everything from and including first comma
            username.truncate(username.find(','));
        }

        if (username.isEmpty())
        {
            username = QString::fromLocal8Bit(userInfo->pw_name);
        }
    }

    insertItem(DesktopIcon("exit", KIcon::SizeMedium),
               i18n("Logout %1").arg(username), this, SLOT(logout()));
}

void TOM::reload()
{
    setInitialized(false);
    initialize();
}

void TOM::contextualizeRMBmenu(KPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu)
{
    if (menuItem == configureMenuID)
    {
        menu->hideContextMenu();
        return;
    }

    ctxMenu->removeItem(contextMenuTitleID);
    QString text = menu->text(menuItem);
    int parens = text.find('(') - 1;
    if (parens > 0)
    {
        text = text.left(parens);
    }
    KPopupTitle* title = new KPopupTitle();
    title->setText(i18n("The \"%2\" Task").arg(text));
    ctxMenu->insertItem(title, contextMenuTitleID, 0);
}

void TOM::slotClear()
{
    KPanelMenu::slotClear();
    m_submenus.clear();
    m_tasks.clear();
}

void TOM::slotExec(int /* id */)
{
    // Reimplemented because we have to
}

void TOM::removeTask()
{
    // TODO: write this change out to the appropriate config file
    QString task = KPopupMenu::contextMenuFocus()->text(KPopupMenu::contextMenuFocusItem());
    if (KMessageBox::warningContinueCancel(this,
                                  i18n("<qt>Are you sure you want to remove the <strong>%1</strong> task?<p>"
                                        "<em>Tip: You can restore the task after it has been removed by selecting the &quot;Modify These Tasks&quot; entry</em></qt>").arg(task),
                                  i18n("Remove Task?"),KStdGuiItem::del()) == KMessageBox::Continue)
    {
        m_tasks.remove(KPopupMenu::contextMenuFocusItem());
        KPopupMenu::contextMenuFocus()->removeItem(KPopupMenu::contextMenuFocusItem());
    }
}

// TODO: should we have a side graphic like the K Menu? personally, i don't
// think it helps usability. it's nice for branding, but that's it. perhaps a
// top image, or something blended with the actual menu background? deffinitely
// a job for a graphic artist.
/*
 * if this goes in, it should be shared w/the kmenu
 *
bool TOM::loadSidePixmap()
{
  KConfig *config = KGlobal::config();
  QColor color = palette().active().highlight();
  QImage image;

  config->setGroup("WM");
  QColor activeTitle = config->readColorEntry("activeBackground", &color);
  QColor inactiveTitle = config->readColorEntry("inactiveBackground", &color);

  config->setGroup("KMenu");
  if (!config->readBoolEntry("Usem_sidePixmap", true))
      return false;

  // figure out which color is most suitable for recoloring to
  int h1, s1, v1, h2, s2, v2, h3, s3, v3;
  activeTitle.hsv(&h1, &s1, &v1);
  inactiveTitle.hsv(&h2, &s2, &v2);
  palette().active().background().hsv(&h3, &s3, &v3);

  if ( (abs(h1-h3)+abs(s1-s3)+abs(v1-v3) < abs(h2-h3)+abs(s2-s3)+abs(v2-v3)) &&
       ((abs(h1-h3)+abs(s1-s3)+abs(v1-v3) < 32) || (s1 < 32)) && (s2 > s1))
    color = inactiveTitle;
  else
    color = activeTitle;

  // limit max/min brightness
  int r, g, b;
  color.rgb(&r, &g, &b);
  int gray = qGray(r, g, b);
  if (gray > 180) {
    r = (r - (gray - 180) < 0 ? 0 : r - (gray - 180));
    g = (g - (gray - 180) < 0 ? 0 : g - (gray - 180));
    b = (b - (gray - 180) < 0 ? 0 : b - (gray - 180));
  } else if (gray < 76) {
    r = (r + (76 - gray) > 255 ? 255 : r + (76 - gray));
    g = (g + (76 - gray) > 255 ? 255 : g + (76 - gray));
    b = (b + (76 - gray) > 255 ? 255 : b + (76 - gray));
  }
  color.setRgb(r, g, b);

  QString sideName = config->readEntry("SideName", "kside.png");
  QString sideTileName = config->readEntry("SideTileName", "kside_tile.png");

  image.load(locate("data", "kicker/pics/" + sideName));

  if (image.isNull())
  {
    return false;
  }

  KIconEffect::colorize(image, color, 1.0);
  m_sidePixmap.convertFromImage(image);

  image.load(locate("data", "kicker/pics/" + sideTileName));

  if (image.isNull())
  {
    return false;
  }

  KIconEffect::colorize(image, color, 1.0);
  m_sideTilePixmap.convertFromImage(image);

  if (m_sidePixmap.width() != m_sideTilePixmap.width())
  {
    return false;
  }

  // pretile the pixmap to a height of at least 100 pixels
  if (m_sideTilePixmap.height() < 100)
  {
    int tiles = (int)(100 / m_sideTilePixmap.height()) + 1;
    QPixmap preTiledPixmap(m_sideTilePixmap.width(), m_sideTilePixmap.height() * tiles);
    QPainter p(&preTiledPixmap);
    p.drawTiledPixmap(preTiledPixmap.rect(), m_sideTilePixmap);
    m_sideTilePixmap = preTiledPixmap;
  }

  return true;
}

void TOM::paletteChanged()
{
    if (!loadSidePixmap())
        m_sidePixmap = m_sideTilePixmap = QPixmap();
}

void TOM::setMinimumSize(const QSize & s)
{
    KPanelMenu::setMinimumSize(s.width() + m_sidePixmap.width(), s.height());
}

void TOM::setMaximumSize(const QSize & s)
{
    KPanelMenu::setMaximumSize(s.width() + m_sidePixmap.width(), s.height());
}

void TOM::setMinimumSize(int w, int h)
{
    KPanelMenu::setMinimumSize(w + m_sidePixmap.width(), h);
}

void TOM::setMaximumSize(int w, int h)
{
    KPanelMenu::setMaximumSize(w + m_sidePixmap.width(), h);
}

QRect TOM::sideImageRect()
{
    return QStyle::visualRect( QRect( frameWidth(), frameWidth(), m_sidePixmap.width(),
                                      height() - 2*frameWidth() ), this );
}

void TOM::resizeEvent(QResizeEvent * e)
{
    setFrameRect( QStyle::visualRect( QRect( m_sidePixmap.width(), 0,
                                      width() - m_sidePixmap.width(), height() ), this ) );
}

void TOM::paintEvent(QPaintEvent * e)
{
    if (m_sidePixmap.isNull()) {
        KPanelMenu::paintEvent(e);
        return;
    }

    QPainter p(this);

    style().drawPrimitive( QStyle::PE_PanelPopup, &p,
                           QRect( 0, 0, width(), height() ),
                           colorGroup(), QStyle::Style_Default,
                           QStyleOption( frameWidth(), 0 ) );

    QRect r = sideImageRect();
    r.setBottom( r.bottom() - m_sidePixmap.height() );
    p.drawTiledPixmap( r, m_sideTilePixmap );

    r = sideImageRect();
    r.setTop( r.bottom() - m_sidePixmap.height() );
    p.drawPixmap( r, m_sidePixmap );

    drawContents( &p );
}

QMouseEvent TOM::translateMouseEvent( QMouseEvent* e )
{
    QRect side = sideImageRect();

    if ( !side.contains( e->pos() ) )
        return *e;

    QPoint newpos( e->pos() );
    QApplication::reverseLayout() ?
        newpos.setX( newpos.x() - side.width() ) :
        newpos.setX( newpos.x() + side.width() );
    QPoint newglobal( e->globalPos() );
    QApplication::reverseLayout() ?
        newglobal.setX( newpos.x() - side.width() ) :
        newglobal.setX( newpos.x() + side.width() );

    return QMouseEvent( e->type(), newpos, newglobal, e->button(), e->state() );
}

void TOM::mousePressEvent(QMouseEvent * e)
{
    QMouseEvent newEvent = translateMouseEvent(e);
    KPanelMenu::mousePressEvent( &newEvent );
}

void TOM::mouseReleaseEvent(QMouseEvent *e)
{
    QMouseEvent newEvent = translateMouseEvent(e);
    KPanelMenu::mouseReleaseEvent( &newEvent );
}

void TOM::mouseMoveEvent(QMouseEvent *e)
{
    QMouseEvent newEvent = translateMouseEvent(e);
    KPanelMenu::mouseMoveEvent( &newEvent );
}*/

extern int kicker_screen_number;

void TOM::runCommand()
{
    QByteArray data;
    QCString appname( "kdesktop" );
    if ( kicker_screen_number )
        appname.sprintf("kdesktop-screen-%d", kicker_screen_number);

    kapp->updateRemoteUserTimestamp( appname );
    kapp->dcopClient()->send( appname, "KDesktopIface",
                              "popupExecuteCommand()", data );
}

void TOM::runTask(int id)
{
    if (!m_tasks.contains(id)) return;

    kapp->propagateSessionManager();
    KApplication::startServiceByDesktopPath(m_tasks[id]->desktopEntryPath(),
      QStringList(), 0, 0, 0, "", true);
}

void TOM::clearRecentDocHistory()
{
    KRecentDocument::clear();
}

void TOM::openRecentDocument(int id)
{
    if (id >= 0)
    {
        kapp->propagateSessionManager();
        KURL u;
        u.setPath(m_recentDocURLs[id]);
        KDEDesktopMimeType::run(u, true);
    }
}

void TOM::logout()
{
    kapp->requestShutDown();
}

#include "tom.moc"