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
|
/* This file is part of the KDE Project
Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "notifierserviceaction.h"
#include <tqdir.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <kstddirs.h>
#include <kdesktopfile.h>
#include <klocale.h>
NotifierServiceAction::NotifierServiceAction()
: NotifierAction()
{
NotifierAction::setIconName("button_cancel");
NotifierAction::setLabel(i18n("Unknown"));
m_service.m_strName = "New Service";
m_service.m_strIcon = "button_cancel";
m_service.m_strExec = "konqueror %u";
}
TQString NotifierServiceAction::id() const
{
if (m_filePath.isEmpty() || m_service.m_strName.isEmpty())
{
return TQString();
}
else
{
return "#Service:"+m_filePath;
}
}
void NotifierServiceAction::setIconName( const TQString &icon )
{
m_service.m_strIcon = icon;
NotifierAction::setIconName( icon );
}
void NotifierServiceAction::setLabel( const TQString &label )
{
m_service.m_strName = label;
NotifierAction::setLabel( label );
updateFilePath();
}
void NotifierServiceAction::execute(KFileItem &medium)
{
KURL::List urls = KURL::List( medium.url() );
KDEDesktopMimeType::executeService( urls, m_service );
}
void NotifierServiceAction::setService(KDEDesktopMimeType::Service service)
{
NotifierAction::setIconName( service.m_strIcon );
NotifierAction::setLabel( service.m_strName );
m_service = service;
updateFilePath();
}
KDEDesktopMimeType::Service NotifierServiceAction::service() const
{
return m_service;
}
void NotifierServiceAction::setFilePath(const TQString &filePath)
{
m_filePath = filePath;
}
TQString NotifierServiceAction::filePath() const
{
return m_filePath;
}
void NotifierServiceAction::updateFilePath()
{
if ( !m_filePath.isEmpty() ) return;
TQString action_name = m_service.m_strName;
action_name.replace( " ", "_" );
TQDir actions_dir( locateLocal( "data", "konqueror/servicemenus/", true ) );
TQString filename = actions_dir.absFilePath( action_name + ".desktop" );
int counter = 1;
while ( TQFile::exists( filename ) )
{
filename = actions_dir.absFilePath( action_name
+ TQString::number( counter )
+ ".desktop" );
counter++;
}
m_filePath = filename;
}
void NotifierServiceAction::setMimetypes(const TQStringList &mimetypes)
{
m_mimetypes = mimetypes;
}
TQStringList NotifierServiceAction::mimetypes()
{
return m_mimetypes;
}
bool NotifierServiceAction::isWritable() const
{
TQFileInfo info( m_filePath );
if ( info.exists() )
{
return info.isWritable();
}
else
{
info = TQFileInfo( info.dirPath() );
return info.isWritable();
}
}
bool NotifierServiceAction::supportsMimetype(const TQString &mimetype) const
{
return m_mimetypes.contains(mimetype);
}
void NotifierServiceAction::save() const
{
TQFile::remove( m_filePath );
KDesktopFile desktopFile(m_filePath);
desktopFile.setGroup(TQString("Desktop Action ") + m_service.m_strName);
desktopFile.writeEntry(TQString("Icon"), m_service.m_strIcon);
desktopFile.writeEntry(TQString("Name"), m_service.m_strName);
desktopFile.writeEntry(TQString("Exec"), m_service.m_strExec);
desktopFile.setDesktopGroup();
desktopFile.writeEntry(TQString("ServiceTypes"), m_mimetypes, ",");
desktopFile.writeEntry(TQString("Actions"),
TQStringList(m_service.m_strName),";");
}
|