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
|
/* This file is part of the KDE project
Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
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; version 2
of the License.
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 <kiconloader.h>
#include <tdeimproxy.h>
#include <tdeapplication.h>
#include <klocale.h>
#include <tdeconfig.h>
#include <tdefiledialog.h>
#include <kurl.h>
#include <konq_popupmenu.h>
#include <tqpixmap.h>
#include <tqdir.h>
#include <tqiconset.h>
#include <tqstringlist.h>
#include "kmetamenu.h"
#include "kdirmenu.h"
#include "kimcontactmenu.h"
#include "kmetamenu.moc"
KMetaMenu::KMetaMenu( TQWidget *parent, const KURL &url,
const TQString &text, const TQString &key, KIMProxy *imProxy )
: TQPopupMenu( parent),
m_root( 0 ), m_home( 0 ), m_etc( 0 ), m_current( 0 ), m_browse( 0 ) {
int recent_no;
group = key;
actions.setAutoDelete( TRUE );
TQStringList dirList;
KURL u;
u.setPath(TQDir::homeDirPath());
if ( kapp->authorizeURLAction("list", u, u) )
{
m_home = new KDirMenu( parent, url, u.path() , text );
insertItem( SmallIcon( "kfm_home" ), i18n("&Home Folder"), m_home);
dirList << u.path();
connect(m_home, TQT_SIGNAL(fileChosen(const TQString &)),
TQT_SLOT(slotFileChosen(const TQString &) ) );
}
u.setPath(TQDir::rootDirPath());
if ( kapp->authorizeURLAction("list", u, u) )
{
m_root = new KDirMenu( parent, url, u.path() , text );
insertItem( SmallIcon( "folder_red" ), i18n("&Root Folder"), m_root);
dirList << u.path();
connect(m_root, TQT_SIGNAL(fileChosen(const TQString &)),
TQT_SLOT(slotFileChosen(const TQString &) ) );
}
TQString confDir = TQDir::rootDirPath()+ "etc";
u.setPath(confDir);
if ( TQFileInfo( confDir ).isWritable() &&
kapp->authorizeURLAction("list", u, u) )
{
m_etc = new KDirMenu( parent, url, confDir, text );
insertItem( SmallIcon( "folder_yellow" ) ,
i18n("&System Configuration"), m_etc);
dirList << confDir;
connect(m_etc , TQT_SIGNAL(fileChosen(const TQString &)),
TQT_SLOT(slotFileChosen(const TQString &) ) );
}
if ( url.isLocalFile()
&& dirList.find( url.path() ) == dirList.end()
&& TQFileInfo( url.path() ).isWritable()
&& TQFileInfo( url.path() ).isDir()
&& kapp->authorizeURLAction("list", url, url) )
//Need to check whether a directory so we don't crash trying to access it
//(#60192)
{
// Also add current working directory
m_current = new KDirMenu( parent, url, url.path(), text );
insertItem( SmallIcon( "folder" ), i18n( "&Current Folder" ),
m_current );
connect(m_current, TQT_SIGNAL(fileChosen(const TQString &)),
TQT_SLOT(slotFileChosen(const TQString &) ) );
}
if ( imProxy )
{
m_contacts = new KIMContactMenu( parent, imProxy );
int item = insertItem( SmallIconSet( "personal" ), i18n( "C&ontact" ), m_contacts );
connect ( m_contacts, TQT_SIGNAL( contactChosen( const TQString &) ), TQT_SIGNAL( contactChosen( const TQString & ) ) );
if ( !imProxy->initialize() || imProxy->fileTransferContacts().isEmpty() )
setItemEnabled( item, false );
}
m_browse = new TDEAction(i18n("&Browse..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotBrowse()), TQT_TQOBJECT(this) );
m_browse->plug(this);
// read the last chosen dirs
// first set the group according to our parameter
conf = kapp->config( );
conf->setGroup(key );
recent_no = conf->readNumEntry("ShowRecent", 5);
list = conf->readPathListEntry("Paths");
if ( list.count() > 0 )
insertSeparator();
int i=1;
TQStringList::Iterator it = list.begin();
while( it != list.end() ) {
if( i == (recent_no + 1) )
break;
TQDir dir( *it );
u.setPath( *it );
if ( !dir.exists() || !kapp->authorizeURLAction("list", u, u) ) {
it = list.remove( it );
continue;
}
TQString escapedDir = *it;
TDEAction *action = new TDEAction(escapedDir.replace("&", "&&"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotFastPath()), TQT_TQOBJECT(this));
action->plug(this );
actions.append( action );
++it;
i++;
}
}
KMetaMenu::KMetaMenu( ){
}
KMetaMenu::~KMetaMenu(){
delete m_root;
delete m_home;
delete m_etc;
delete m_current;
delete m_browse;
actions.clear();
}
void KMetaMenu::slotFileChosen(const TQString &path ){
writeConfig(path );
emit fileChosen(path );
}
void KMetaMenu::slotFastPath( ) {
TDEAction *action;
action = (TDEAction*) sender();
TQString text = action->plainText( );
slotFileChosen( text );
}
void KMetaMenu::writeConfig( const TQString &path){
list.remove(path );
list.prepend(path );
conf->setGroup( group );
int c = conf->readNumEntry( "ShowRecent", 5 );
while ( list.count() > c && !list.isEmpty() )
list.remove(list.last());
conf->writePathEntry("Paths", list);
conf->sync( );
}
void KMetaMenu::slotBrowse() {
KURL dest = KFileDialog::getExistingURL();
if( dest.isEmpty() ) return;
slotFileChosen( dest.isLocalFile() ? dest.path() : dest.url() );
}
|