summaryrefslogtreecommitdiffstats
path: root/quanta/project/uploadprofiles.cpp
blob: 669971cefd2c8087d9196f7c235462aa3b327df3 (plain)
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
/***********************************************************************
                          uploadprofiles.cpp  -  extended Map of UploadProfiles
                             -------------------
    begin                : July 11 2004
    copyright            : (C) 2004 by Jens Herden <[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.                                   *
 *                                                                         *
 ***************************************************************************/

// qt includes
#include <tqobject.h>

// KDE includes
#include <kiconloader.h>
#include <klocale.h>

// app includes
#include "servertreeview.h"
#include "uploadprofiles.h"
#include "quanta.h"
#include "resource.h"
#include "project.h"


UploadProfiles::UploadProfiles() : UploadProfileMap()
{
}


void UploadProfiles::readFromXML(const TQDomDocument &dom)
{
  clear();  // empty the list
  m_profilesNode = dom.firstChild().firstChild().namedItem("uploadprofiles");
  if (m_profilesNode.isNull())
    return;

  TQDomNodeList profileList = m_profilesNode.toElement().elementsByTagName("profile");
  UploadProfile newProfile;
  for (uint i = 0; i < profileList.count(); i++)
  {
    newProfile.domElement = profileList.item(i).toElement();
    newProfile.name = newProfile.domElement.attribute("name");
    newProfile.treeview = createTreeview(newProfile);
    insert(newProfile.name, newProfile);
  }
}


bool UploadProfiles::removeFromMapAndXML(const TQString &name)
{
  UploadProfiles::Iterator it = find(name);
  if ( it == end() )
    return false;
  // ok now remove
  TQDomElement el = (*it).domElement;
  el.parentNode().removeChild(el);
  erase(name);
  return true;
}

void UploadProfiles::clear()
{
  // remove all treeviews
  for (UploadProfiles::iterator it = begin(); it != end(); ++it)
  {
    if ( (*it).treeview )
    {
      quantaApp->deleteToolWindow( (*it).treeview );
    }
  }
  // clear the map
  UploadProfileMap::clear();
}

TQWidget * UploadProfiles::createTreeview(const UploadProfile &profile)
{
  TQWidget *widget = 0L;
  KURL kurl = url(profile.domElement);
  if (kurl.isValid() && ! kurl.isEmpty())
  {
    widget = new ServerTreeView(quantaApp->config(), quantaApp, kurl, "ServerTreeView" + profile.name);
    widget->setIcon(SmallIcon("up"));
    widget->setCaption( i18n("Upload Profile") + ": " + profile.name );
    quantaApp->addToolWindow(widget, quantaApp->prevDockPosition(widget, KDockWidget::DockRight), quantaApp->getMainDockWidget());
  }
  return widget;
}


KURL UploadProfiles::url(const TQDomElement &e)
{
  TQString protocol = e.attribute("remote_protocol","ftp") + "://";
  TQString s = protocol;
  TQString host = e.attribute("remote_host","");
  s += host;
  TQString port = e.attribute("remote_port","");
  if (! port.isEmpty()) {
    s += ":" + port;
  }
  s += e.attribute("remote_path","");
  KURL url = KURL::fromPathOrURL(s);
  TQString user = e.attribute("user","");
  if (!user.isEmpty()) {
    url.setUser(user);
  }
  // check if we know the password
  if ( !user.isEmpty() && Project::ref()->keepPasswd )
  {
    TQString password = Project::ref()->password(protocol + user + "@" + host);
    url.setPass(password);
  }
  return url;
}