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
|
/* KPilot
**
** Copyright (C) 1998-2001 by Dan Pilone
**
** This is a class that does "the work" of adding and deleting
** files in the pending_install directory of KPilot. It is used
** by the fileInstallWidget and by the daemon's drag-and-drop
** file accepter.
*/
/*
** 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 in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/
/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/
#include "options.h"
#include <unistd.h>
#include <tqstring.h>
#include <tqstrlist.h>
#include <tqdir.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kurl.h>
#include <kio/netaccess.h>
#include <kmessagebox.h>
#include "fileInstaller.moc"
FileInstaller::FileInstaller() :
enabled(true)
{
FUNCTIONSETUP;
fDirName = KGlobal::dirs()->saveLocation("data",
CSL1("kpilot/pending_install/"));
fPendingCopies = 0;
}
/* virtual */ FileInstaller::~FileInstaller()
{
FUNCTIONSETUP;
}
void FileInstaller::clearPending()
{
FUNCTIONSETUP;
unsigned int i;
TQDir installDir(fDirName);
// Start from 2 to skip . and ..
//
for (i = 2; i < installDir.count(); i++)
{
TQFile::remove(fDirName + installDir[i]);
}
if (i > 2)
{
emit filesChanged();
}
}
void FileInstaller::deleteFile(const TQString &file)
{
TQFile::remove(fDirName + file);
emit filesChanged();
}
void FileInstaller::deleteFiles(const TQStringList &files)
{
if(files.empty())
return;
for(TQStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
TQFile::remove(fDirName + *it);
emit filesChanged();
}
/* virtual */ bool FileInstaller::runCopy(const TQString & s, TQWidget* w )
{
FUNCTIONSETUP;
if(!(s.endsWith(CSL1(".pdb"), false) || s.endsWith(CSL1(".prc"), false))) {
KMessageBox::detailedSorry(w, i18n("Cannot install %1").arg(s),
i18n("Only PalmOS database files (like *.pdb and *.prc) can be installed by the file installer."));
return false;
}
#ifdef DEBUG
DEBUGKPILOT << fname << ": Copying " << s << endl;
#endif
KURL srcName;
srcName.setPath(s);
KURL destDir(fDirName + CSL1("/") + srcName.fileName());
#if KDE_IS_VERSION(3,1,9)
return KIO::NetAccess::copy(srcName, destDir, w);
#else
return KIO::NetAccess::copy(srcName,destDir);
#endif
}
void FileInstaller::addFiles(const TQStringList & fileList, TQWidget* w)
{
FUNCTIONSETUP;
if (!enabled) return;
unsigned int succ = 0;
for(TQStringList::ConstIterator it = fileList.begin();
it != fileList.end(); ++it)
{
if (runCopy( *it, w ))
succ++;
}
if (succ)
{
emit filesChanged();
}
}
void FileInstaller::addFile( const TQString & file, TQWidget* w )
{
FUNCTIONSETUP;
if (!enabled) return;
if (runCopy(file, w))
{
emit(filesChanged());
}
}
/* slot */ void FileInstaller::copyCompleted()
{
FUNCTIONSETUP;
}
const TQStringList FileInstaller::fileNames() const
{
FUNCTIONSETUP;
TQDir installDir(fDirName);
return installDir.entryList(TQDir::Files |
TQDir::NoSymLinks | TQDir::Readable);
}
/* slot */ void FileInstaller::setEnabled(bool b)
{
FUNCTIONSETUP;
enabled=b;
}
|