summaryrefslogtreecommitdiffstats
path: root/src/torkapplet/tork_mnu.cpp
blob: 29e96b0a8cd32f1db46f71d5ad742a31ceeada04 (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
/***************************************************************************
** $Id: tork_mnu.cpp,v 1.7 2008/07/31 19:56:29 hoganrobert Exp $
 *   Copyright (C) 2006 - 2008 Robert Hogan                                *
 *   robert@roberthogan.net                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

#include <ntqdir.h>
#include <ntqfileinfo.h>
#include <ntqstringlist.h>

#include <tdeapplication.h>
#include <tdeglobal.h>
#include <kiconloader.h>
#include <tdeio/global.h>
#include <tdelocale.h>
#include <krun.h>
#include <kshell.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include <dcopref.h>
#include <dcopclient.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <krun.h>

#include "tork_mnu.h"
#include "../functions.h"

K_EXPORT_KICKER_MENUEXT(tork, TorkMenu)

TQValueVector<TQString> torkifyApp(8);


TorkMenu::TorkMenu(TQWidget *parent, const char *name, const TQStringList& /* args */)
    : KPanelMenu("", parent, name),m_kdestate(true)
{
    p_dcopServer= new DCOPClient();
    p_dcopServer->attach ();

}

TorkMenu::~TorkMenu()
{
    TDEGlobal::locale()->removeCatalogue("libkickermenu_tork");
    p_dcopServer->detach();
    delete p_dcopServer;

}

void TorkMenu::initialize()
{
    if (initialized())
    {
        clear();
    }
    else
    {
        kapp->iconLoader()->addAppDir("tork");
    }

    setInitialized(true);

    torkifyApp[5] = "Konversation";
    torkifyApp[2] = "Kopete";
    torkifyApp[4] = "Gaim";
    torkifyApp[3] = "Pidgin";
    torkifyApp[6] = "Konsole";
    torkifyApp[1] = "Opera";
    torkifyApp[0] = "Firefox";
    torkifyApp[7] = "Email";

    TQStringList paths = getProgramList();


    if (paths.contains("firefox"))
        insertItem( SmallIcon("tork_firefox"), i18n( "Anonymous Firefox" ), 0,1 );
    if (paths.contains("opera"))
        insertItem( SmallIcon("tork_opera"), i18n( "Anonymous Opera" ), 1,2 );
    if (paths.contains("kopete"))
        insertItem( SmallIcon("kopete"), i18n( "Anonymous Kopete" ), 2,3 );
    if (paths.contains("pidgin"))
        insertItem( SmallIcon("pidgin"), i18n( "Anonymous Pidgin" ), 3,4 );
    if (paths.contains("gaim"))
        insertItem( SmallIcon("gaim"), i18n( "Anonymous Gaim" ), 4,5 );
    if (paths.contains("konversation"))
        insertItem( SmallIcon("konversation"), i18n( "Anonymous Konversation" ), 5,6 );
    if (paths.contains("konsole"))
        insertItem( SmallIcon("tork_konsole"), i18n( "Anonymous Konsole Session" ), 6,7 );
    insertSeparator();

    
    insertItem( SmallIcon("tork_mail"), i18n( "Send Anonymous Email" ), 7,8 );

    insertSeparator();
    
    insertItem( SmallIcon("tork_konqueroron"), i18n( "Anonymize KDE" ), 9,9 );

    connect( this, SIGNAL( aboutToShow() ), SLOT( showPopup() ));

}

void TorkMenu::showPopup()
{
    bool anonymized = false;


    if (p_dcopServer->isApplicationRegistered ("tork"))
    {
        DCOPRef tork( "tork", "DCOPTork" );
        anonymized = tork.call( "getKDESetting" );
    }

    if (anonymized)
        changeItem(9, SmallIcon("tork_konqueroroff"), i18n( "De-Anonymize KDE" ));
    else
        changeItem(9, SmallIcon("tork_konqueroron"), i18n( "Anonymize KDE" ));


}

void TorkMenu::slotExec(int id)
{

    m_torkrunning = false;
    if (p_dcopServer->isApplicationRegistered ("tork"))
            m_torkrunning = true;
    

	switch(id)
	{
	case 9:
		anonymizeKDE(); break;
	default:
		anonymousApp(id);break;
	}

}

void TorkMenu::anonymousApp(int id)
{
    
    TQString app = torkifyApp[id];
    app.prepend("anonymous");

    if (m_torkrunning){
        DCOPRef("tork*", "DCOPTork").send("startEverything");
        DCOPRef("tork*", "DCOPTork").send(TQCString(app));
    }else
        KRun::runCommand( TQString("tork --%1").arg(app), "tork", "tork" );

}


void TorkMenu::anonymizeKDE()
{
    if (m_torkrunning){
        DCOPRef("tork*", "DCOPTork").send("startEverything");
        DCOPRef("tork*", "DCOPTork").send("toggleKDESetting");
    }else
        KRun::runCommand( "tork --toggleKDE", "tork", "tork" );

//     if (m_kdestate)
//         changeItem(9, SmallIcon("tork_konqueroroff"), i18n( "De-Anonymize KDE" ));
//     else
//         changeItem(9, SmallIcon("tork_konqueroron"), i18n( "Anonymize KDE" ));
// 
//     m_kdestate = !m_kdestate;

}

TQStringList TorkMenu::getProgramList()
{

    //Check for the existence of anonymizable/helper programs first.
    TQStringList programList;
    programList << "firefox" << "kopete" << "gaim" <<
                               "pidgin" << "opera" << "konversation";

    return findPrograms(programList);
}

#include "tork_mnu.moc"