Add missing files
[klaudia.git] / src / mainw.py
blobbad29e9250ce1ca31a48a34b8289826b344c8997
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 #Imports
6 from os import path
7 from PyQt4.QtCore import QFile, QIODevice
8 from PyQt4.QtXml import QDomDocument
9 from PyKDE4.kdecore import i18n
10 from PyKDE4.kdeui import KMessageBox, KXmlGuiWindow
11 import shared, ui_mainw
14 # Main Window
15 class KlaudiaMainW(KXmlGuiWindow, ui_mainw.Ui_KlaudiaMainW):
16 def __init__(self, *args):
17 KXmlGuiWindow.__init__(self, *args)
18 self.setupUi(self)
20 # Load a project if an argument is given
21 if (shared.OpenFolder):
22 url = shared.OpenFolder
23 if (path.exists(url+"/project.klaudia")):
24 shared.p_folder = url
25 shared.setIconFromFolder(url)
26 else:
27 KMessageBox.sorry(self, i18n("The Klaudia project cannot be loaded!"), i18n("Sorry"))
28 shared.exit_(-1)
30 # Read project file
31 xml = QDomDocument()
32 filename = QFile(shared.p_folder+"/project.klaudia")
33 if not filename.open(QIODevice.ReadOnly):
34 print "error here, 1"
35 if not xml.setContent(filename):
36 print "error here, 2"
37 filename.close()
39 # Check if project file is not corrupted
40 content = xml.documentElement()
41 if (content.tagName() != "KLAUDIA"):
42 print "error here, 3"
44 # Get values from XML - the big code
45 node = content.firstChild()
46 while not node.isNull():
47 if (node.toElement().tagName() == "Properties"):
48 properties = node.toElement().firstChild()
49 while not properties.isNull():
50 name = properties.toElement().tagName()
51 text = properties.toElement().text()
52 if (name == "Name"): shared.p_name = text
53 elif (name == "Author"): shared.p_author = text
54 elif (name == "Composer"): shared.p_composer = text
55 elif (name == "Album"): shared.p_album = text
56 elif (name == "Track"): shared.p_track = text
57 elif (name == "BPM"): shared.p_bpm = text
58 elif (name == "Time-Start"): shared.p_time_start = text
59 elif (name == "Time-End"): shared.p_time_end = text
60 properties = properties.nextSibling()
61 node = node.nextSibling()