~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/adhoc_fileserver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * adhoc_fileserver.cpp - Implementation of a personal ad-hoc fileserver
 
3
 * Copyright (C) 2005  Remko Troncon
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#include <qdir.h>
 
22
#include <qfileinfo.h>
 
23
 
 
24
#include "common.h"
 
25
#include "psiaccount.h"
 
26
#include "adhoc_fileserver.h"
 
27
#include "xmpp_xdata.h"
 
28
 
 
29
using namespace XMPP;
 
30
 
 
31
bool AHFileServer::isAllowed(const Jid& j) const
 
32
{
 
33
        return manager()->account()->jid().compare(j,false);
 
34
}
 
35
 
 
36
AHCommand AHFileServer::execute(const AHCommand& c, const Jid& requester)
 
37
{
 
38
        // Extract the file
 
39
        QString file;
 
40
        if (c.hasData()) {
 
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();
 
46
                        }
 
47
                }
 
48
        }
 
49
        else {
 
50
                file = QDir::currentDirPath();
 
51
        }
 
52
 
 
53
        if (QFileInfo(file).isDir()) {
 
54
                // Return a form with a filelist
 
55
                XData form;
 
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;
 
60
 
 
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);
 
66
 
 
67
                XData::Field::OptionList file_options;
 
68
        QDir d(file);
 
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;
 
77
                }
 
78
                files_field.setOptions(file_options);
 
79
                fields += files_field;
 
80
                
 
81
                form.setFields(fields);
 
82
 
 
83
                return AHCommand::formReply(c, form);
 
84
        }
 
85
        else {
 
86
                QStringList l(file);
 
87
                manager()->account()->sendFiles(requester,l,true);
 
88
                return AHCommand::completedReply(c);
 
89
        }
 
90
}