]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
slowly progressing... ruler scrubbing, start of trackview
[kdenlive] / src / kdenlivedoc.cpp
1 /***************************************************************************
2                         kdenlivedoc.cpp  -  description
3                            -------------------
4   begin                : Fri Nov 22 2002
5   copyright            : (C) 2002 by Jason Wood
6   email                : jasonwood@blueyonder.co.uk
7   copyright            : (C) 2005 Lucio Flavio Correa
8   email                : lucio.correa@gmail.com
9   copyright            : (C) Marco Gittler
10   email                : g.marco@freenet.de
11   copyright            : (C) 2006 Jean-Baptiste Mardelle
12   email                : jb@ader.ch
13
14 ***************************************************************************/
15
16 /***************************************************************************
17  *                                                                         *
18  *   This program is free software; you can redistribute it and/or modify  *
19  *   it under the terms of the GNU General Public License as published by  *
20  *   the Free Software Foundation; either version 2 of the License, or     *
21  *   (at your option) any later version.                                   *
22  *                                                                         *
23  ***************************************************************************/
24
25
26 #include <KDebug>
27 #include <KStandardDirs>
28 #include <KMessageBox>
29 #include <KLocale>
30 #include <KFileDialog>
31 #include <KIO/NetAccess>
32
33
34 #include "kdenlivedoc.h"
35
36 KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
37 {
38   if (!url.isEmpty()) {
39     QString tmpFile;
40     if(KIO::NetAccess::download(url.path(), tmpFile, parent))
41     {
42       QFile file(tmpFile);
43       m_document.setContent(&file, false);
44       file.close();
45       m_projectName = url.fileName();
46       KIO::NetAccess::removeTempFile(tmpFile);
47     }
48     else
49     {
50       KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
51     }
52   }
53   else {
54     // Creating new document
55     QDomElement westley = m_document.createElement("westley");
56     m_document.appendChild(westley);
57     QDomElement doc = m_document.createElement("kdenlivedoc");
58     doc.setAttribute("version", "0.6");
59     westley.appendChild(doc);
60     QDomElement props = m_document.createElement("properties");
61     doc.setAttribute("width", m_width);
62     doc.setAttribute("height", m_height);
63     doc.setAttribute("projectfps", m_fps);
64     doc.appendChild(props);
65     
66   }
67   if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
68     else m_timecode.setFormat((int) fps);
69 }
70
71 KdenliveDoc::~KdenliveDoc()
72 {
73 }
74
75 QDomDocument KdenliveDoc::toXml()
76 {
77   return m_document;
78 }
79
80 Timecode KdenliveDoc::timecode()
81 {
82   return m_timecode;
83 }
84
85 QString KdenliveDoc::documentName()
86 {
87   return m_projectName;
88 }
89
90 QDomNodeList KdenliveDoc::producersList()
91 {
92   return m_document.elementsByTagName("producer");
93 }
94
95 void KdenliveDoc::setProducers(QDomElement doc)
96 {
97   QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
98
99   QDomNodeList list = m_document.elementsByTagName("producer");
100   int ct = list.count();
101     kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
102   for (int i = 0; i < ct; i++) {
103     kdenlivedocument.removeChild(list.item(0));
104    }
105
106   QDomNode n = doc.firstChild();
107   ct = 0;
108   while(!n.isNull()) {
109      QDomElement e = n.toElement(); // try to convert the node to an element.
110      if(!e.isNull() && e.tagName() == "producer") {
111          kdenlivedocument.appendChild(m_document.importNode(e, true));
112         ct++;
113      }
114      n = n.nextSibling();
115   }
116   kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
117   //kDebug()<<m_document.toString();
118 }
119
120 double KdenliveDoc::fps()
121 {
122   return m_fps;
123 }
124
125 int KdenliveDoc::width()
126 {
127   return m_width;
128 }
129
130 int KdenliveDoc::height()
131 {
132   return m_height;
133 }
134
135 #include "kdenlivedoc.moc"
136