2
* adhoc_fileserver.cpp - Implementation of a personal ad-hoc fileserver
3
* Copyright (C) 2005 Remko Troncon
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include <qfileinfo.h>
25
#include "psiaccount.h"
26
#include "adhoc_fileserver.h"
27
#include "xmpp_xdata.h"
31
bool AHFileServer::isAllowed(const Jid& j) const
33
return manager()->account()->jid().compare(j,false);
36
AHCommand AHFileServer::execute(const AHCommand& c, const Jid& requester)
41
QString fileName, curDir;
42
XData::FieldList fl = c.data().fields();
43
for (unsigned int i=0; i < fl.count(); i++) {
44
if (fl[i].var() == "file" && !(fl[i].value().isEmpty())) {
45
file = fl[i].value().first();
50
file = QDir::currentDirPath();
53
if (QFileInfo(file).isDir()) {
54
// Return a form with a filelist
56
form.setTitle(QObject::tr("Choose file"));
57
form.setInstructions(QObject::tr("Choose a file"));
58
form.setType(XData::Data_Form);
59
XData::FieldList fields;
61
XData::Field files_field;
62
files_field.setType(XData::Field::Field_ListSingle);
63
files_field.setVar("file");
64
files_field.setLabel(QObject::tr("File"));
65
files_field.setRequired(true);
67
XData::Field::OptionList file_options;
69
//d.setFilter(QDir::Files|QDir::Hidden|QDir::NoSymLinks);
70
QStringList l = d.entryList();
71
for (QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
72
XData::Field::Option file_option;
73
QFileInfo fi(QDir(file).filePath(*it));
74
file_option.label = *it + (fi.isDir() ? QString(" [DIR]") : QString(" (%1 bytes)").arg(QString::number(fi.size())));
75
file_option.value = QDir(file).absFilePath(*it);
76
file_options += file_option;
78
files_field.setOptions(file_options);
79
fields += files_field;
81
form.setFields(fields);
83
return AHCommand::formReply(c, form);
87
manager()->account()->sendFiles(requester,l,true);
88
return AHCommand::completedReply(c);