summaryrefslogtreecommitdiffstats
path: root/quanta/project/projectlist.cpp
blob: db162ce2765f9836bb0f9682cc7856c95a200548 (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
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
185
186
187
/***********************************************************************
                          projectlist.cpp  -  List of ProjectURL's
                             -------------------
    begin                : June 19 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 <tqdom.h>
#include <tqstring.h>
#include <tqfileinfo.h>

// kde includes
#include <kprogress.h>

#include "projectlist.h"
#include "projecturl.h"
#include "resource.h"
#include "quantacommon.h"


ProjectList::ProjectList(int size) : ProjectUrlList(size)
{
}


void ProjectList::clear()
{
  m_baseURL = KURL();
  ProjectUrlList::clear();
}

bool ProjectList::readFromXML(TQDomDocument &dom, const KURL &baseURL,
                                 const KURL &/*templateURL*/, const TQRegExp &excludeRx)
{
  clear();  // empty the list
  m_baseURL = baseURL; // remember this
  bool modified = false;
  TQDomElement el;
  TQDomNodeList nl = dom.firstChild().firstChild().childNodes();
  progressBar->setTotalSteps(nl.count() - 1);
  progressBar->setValue(0);
  progressBar->setTextEnabled(true);
  TQString path;
  TQString tmpString;
  uint nlCount = nl.count();
  for ( uint i = 0; i < nlCount; i++ )
  {
    KURL url = baseURL;
    el = nl.item(i).toElement();
    tmpString = el.attribute("url");
    if (!tmpString.isEmpty())
    {
      QuantaCommon::setUrl(url,tmpString);
      //Compatibility conversion
      if (tmpString != QuantaCommon::qUrl(url))
      {
        el.setAttribute("url", QuantaCommon::qUrl(url));
        modified = true;
      }
    }
    path = url.path();
    url = TQExtFileInfo::toAbsolute(url, baseURL);
    if ( el.nodeName() == "item" )
    {
      if (excludeRx.exactMatch(path) || tqfind(url.url(-1)))
      {
        el.tqparentNode().removeChild(el);
        modified = true;
        i--;
      } else
      {
        bool docFolder = (el.attribute("documentFolder", "false") == "true");
        int uploadtqStatus = el.attribute("uploadstatus", "-1").toInt();
        if (uploadtqStatus == -1)
          el.setAttribute("uploadstatus", 1);
        //remove non-existent local files
        if ( url.isLocalFile() )
        {
          TQFileInfo fi( url.path() );
          if ( !fi.exists() )
          {
            el.tqparentNode().removeChild( el );
            modified = true;
            i--;
          } else
          {
            insert(url.url(-1), new ProjectURL(url, el.attribute("desc"), el.attribute("uploadstatus", "1").toInt(),
                                             docFolder, el));
          }
        } else
        {
            insert(url.url(-1), new ProjectURL(url, el.attribute("desc"), el.attribute("uploadstatus", "1").toInt(),
                                             docFolder, el));
        }
      }
    }
    progressBar->advance(1);
  }
  ProjectURL *proUrl = tqfind(baseURL);
  if (!proUrl)
  {
      el = dom.createElement("item");
      el.setAttribute("url", "");
      el.setAttribute("uploadstatus", "1");
      dom.firstChild().firstChild().appendChild(el);
      insert(baseURL.url(-1), new ProjectURL(baseURL, "", ProjectURL::AlwaysUpload,
                                             true, el));
      modified = true;
  }
  progressBar->setTotalSteps(1);
  progressBar->setValue(0);
  progressBar->setTextEnabled(false);
  return modified;
}


bool ProjectList::removeFromListAndXML(const KURL &url)
{
  ProjectURL *p = tqfind(url);
  if (p) {
    TQDomElement el = p->domElement;
    el.tqparentNode().removeChild(el);
    remove(url.url(-1));
    return true;
  }
  return false;
}


bool ProjectList::tqcontains(const KURL &url) const
{
  return ProjectUrlList::tqfind(url.url(-1));
}


ProjectURL * ProjectList::tqfind(const KURL &url) const
{
  return ProjectUrlList::tqfind(url.url(-1));
}


void ProjectList::insert(ProjectURL *url)
{
  ProjectUrlList::insert(url->url(-1), url);
}


bool ProjectList::isFolder(const KURL &url) const
{
  ProjectURL *p = tqfind(url);
  return ( p && url.url(-1) != (*p).url() );
}


void ProjectList::insert(const TQString & key, const ProjectURL * item)
{
  ProjectUrlList::insert(key, item);
}


ProjectURL * ProjectList::tqfind ( const TQString & key ) const
{
  return ProjectUrlList::tqfind(key);
}


bool ProjectList::remove ( const TQString & key )
{
  return ProjectUrlList::remove(key);
}


void ProjectList::tqreplace(const TQString & key, const ProjectURL * item)
{
  ProjectUrlList::tqreplace(key, item);
}