summaryrefslogtreecommitdiffstats
path: root/kicker/menuext/tdeprint/print_mnu.cpp
blob: e611b039ef225df8337226e0fbe6157d276455f2 (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
/*****************************************************************

Copyright (c) 1996-2001 the kicker authors. See file AUTHORS.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************/

#include "print_mnu.h"
#include <kiconloader.h>
#include <klocale.h>
#include <kglobal.h>
#include <kapplication.h>
#include <krun.h>
#include <tdeprint/kmmanager.h>
#include <tqregexp.h>

K_EXPORT_KICKER_MENUEXT(tdeprint, PrintMenu)

#define ADD_PRINTER_ID		0
#define TDEPRINT_SETTINGS_ID	1
#define	CONFIG_SERVER_ID	2
#define	PRINT_MANAGER_ID	3
#define PRINT_BROWSER_ID	4
#define	KPRINTER_ID		5
#define PRINTER_LIST_ID		10

PrintMenu::PrintMenu(TQWidget *parent, const char *name, const TQStringList & /*args*/)
: KPanelMenu("", parent, name)
{
    static bool tdeprintIconsInitialized = false;
    if ( !tdeprintIconsInitialized ) {
        TDEGlobal::iconLoader()->addAppDir("tdeprint");
        tdeprintIconsInitialized = true;
    }
}

PrintMenu::~PrintMenu()
{
}

void PrintMenu::initialize()
{
    if (initialized()) clear();
    setInitialized(true);

    int ID = PRINTER_LIST_ID;
    // just to be sure the plugin is loaded -> icons are available
    KMManager::self();

    if ((KMManager::self()->printerOperationMask() & KMManager::PrinterCreation) && KMManager::self()->hasManagement())
        insertItem(SmallIconSet("wizard"), i18n("Add Printer..."), ADD_PRINTER_ID);
    insertItem(SmallIconSet("tdeprint_configmgr"), i18n("TDE Print Settings"), TDEPRINT_SETTINGS_ID);
    if (KMManager::self()->serverOperationMask() & KMManager::ServerConfigure)
        insertItem(SmallIconSet("tdeprint_configsrv"), i18n("Configure Server"), CONFIG_SERVER_ID);
    insertSeparator();
    insertItem(SmallIconSet("kcontrol"), i18n("Print Manager"), PRINT_MANAGER_ID);
    insertItem(SmallIconSet("konqueror"), i18n("Print Browser (Konqueror)"), PRINT_BROWSER_ID);
    insertSeparator();
    insertItem(SmallIconSet("fileprint"), i18n("Print File..."), KPRINTER_ID);

    // printer list
    TQPtrList<KMPrinter>    *l = KMManager::self()->printerList();
    if (l && !l->isEmpty())
    {
        bool separatorInserted = false;
        TQPtrListIterator<KMPrinter>    it(*l);
        for (; it.current(); ++it)
        {
            // no special, implicit or pure instances
            if (it.current()->isSpecial() || it.current()->isVirtual())
                continue;
            if (!separatorInserted)
            {
                // we insert a separator only when we find the first
                // printer
                insertSeparator();
                separatorInserted = true;
            }
            insertItem(SmallIconSet(it.current()->pixmap()),
                       it.current()->printerName(), ID++);
        }
    }
}

void PrintMenu::slotExec(int ID)
{
    switch (ID)
    {
        case ADD_PRINTER_ID:
            kapp->tdeinitExec("kaddprinterwizard");
            break;
        case TDEPRINT_SETTINGS_ID:
	    kapp->tdeinitExec("kaddprinterwizard", TQStringList("--tdeconfig"));
            break;
	case CONFIG_SERVER_ID:
	    kapp->tdeinitExec("kaddprinterwizard", TQStringList("--serverconfig"));
	    break;
        case PRINT_MANAGER_ID:
            KRun::runCommand("tdecmshell tde-printers.desktop");
            break;
        case PRINT_BROWSER_ID:
            KRun::runCommand("kfmclient openProfile filemanagement print:/", "kfmclient", "konqueror");
            break;
	case KPRINTER_ID:
	    kapp->tdeinitExec("kprinter");
	    break;
        default:
            {
                // start kjobviewer
                TQStringList args;
                args << "--show" << "-d" << text(ID).remove('&');
                kapp->tdeinitExec("kjobviewer", args);
            }
            break;
    }
}

void PrintMenu::reload()
{
	initialize();
}

#include "print_mnu.moc"