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
|
/*
*
* $Id: k3bdiroperator.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2003 Sebastian Trueg <[email protected]>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
*
* 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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bdiroperator.h"
#include <k3bapplication.h>
#include <k3b.h>
#include <k3bcore.h>
#include <kcombiview.h>
#include <tdefilepreview.h>
#include <tdeaction.h>
#include <kbookmarkmenu.h>
#include <kstandarddirs.h>
#include <tdepopupmenu.h>
#include <tqdir.h>
K3bDirOperator::K3bDirOperator(const KURL& url, TQWidget* parent, const char* name )
: KDirOperator( url, parent, name )
{
setViewConfig( k3bcore->config(), "file view" );
setMode( KFile::Files );
// disable the del-key since we still have a focus problem and users keep
// deleting files when they want to remove project entries
TDEAction* aDelete = actionCollection()->action("delete");
if( aDelete )
aDelete->setShortcut( 0 );
// add the bookmark stuff
KBookmarkManager* bmMan = KBookmarkManager::managerForFile( locateLocal( "data", "k3b/bookmarks.xml" ), false );
bmMan->setEditorOptions( i18n("K3b Bookmarks"), false );
bmMan->setUpdate( true );
bmMan->setShowNSBookmarks( false );
m_bmPopup = new TDEActionMenu( i18n("Bookmarks"), "bookmark", this, "bookmarks" );
m_bmMenu = new KBookmarkMenu( bmMan, this, m_bmPopup->popupMenu(), actionCollection(), true );
(void)new TDEAction( i18n("&Add to Project"), SHIFT+Key_Return,
this, TQT_SLOT(slotAddFilesToProject()),
actionCollection(), "add_file_to_project");
}
K3bDirOperator::~K3bDirOperator()
{
delete m_bmMenu;
}
void K3bDirOperator::readConfig( TDEConfig* cfg, const TQString& group )
{
TQString oldGroup = cfg->group();
cfg->setGroup( group );
KDirOperator::readConfig( cfg, group );
setView( KFile::Default );
//
// There seems to be a bug in the KDELibs which makes setURL crash on
// some systems when used with a non-existing url
//
TQString lastUrl = cfg->readPathEntry( "last url", TQDir::home().absPath() );
while( !TQFile::exists(lastUrl) ) {
TQString urlUp = lastUrl.section( '/', 0, -2 );
if( urlUp == lastUrl )
lastUrl = TQDir::home().absPath();
else
lastUrl = urlUp;
}
setURL( KURL::fromPathOrURL(lastUrl), true );
cfg->setGroup( oldGroup );
emit urlEntered( url() );
}
void K3bDirOperator::writeConfig( TDEConfig* cfg, const TQString& group )
{
TQString oldGroup = cfg->group();
cfg->setGroup( group );
KDirOperator::writeConfig( cfg, group );
cfg->writePathEntry( "last url", url().path() );
cfg->setGroup( oldGroup );
}
void K3bDirOperator::openBookmarkURL( const TQString& url )
{
setURL( KURL::fromPathOrURL( url ), true );
}
TQString K3bDirOperator::currentTitle() const
{
return url().path(-1);
}
TQString K3bDirOperator::currentURL() const
{
return url().path(-1);
}
void K3bDirOperator::activatedMenu( const KFileItem*, const TQPoint& pos )
{
// both from KDirOperator
setupMenu();
updateSelectionDependentActions();
// insert our own actions
TDEActionMenu* dirOpMenu = (TDEActionMenu*)actionCollection()->action("popupMenu");
dirOpMenu->insert( new TDEActionSeparator( actionCollection() ) );
dirOpMenu->insert( m_bmPopup );
dirOpMenu->insert( actionCollection()->action("add_file_to_project"), 0 );
dirOpMenu->insert( new TDEActionSeparator( actionCollection() ), 1 );
bool hasSelection = view() && view()->selectedItems() &&
!view()->selectedItems()->isEmpty();
actionCollection()->action("add_file_to_project")->setEnabled( hasSelection && k3bappcore->k3bMainWindow()->activeView() != 0 );
dirOpMenu->popup( pos );
}
void K3bDirOperator::slotAddFilesToProject()
{
KURL::List files;
for( TQPtrListIterator<KFileItem> it( *(selectedItems()) ); it.current(); ++it ) {
files.append( it.current()->url() );
}
if( !files.isEmpty() )
k3bappcore->k3bMainWindow()->addUrls( files );
}
#include "k3bdiroperator.moc"
|