2 # -*- coding: utf-8 -*-
7 import shared
, ui_wizard
8 from random
import randint
9 from PyQt4
.QtCore
import QFile
, QIODevice
, QTextStream
, SIGNAL
10 from PyQt4
.QtGui
import QWizard
11 from PyKDE4
.kdecore
import i18n
12 from PyKDE4
.kdeui
import KIconLoader
, KMessageBox
16 class WizardW(QWizard
, ui_wizard
.Ui_WizardW
):
17 def __init__(self
, *args
):
18 QWizard
.__init
__(self
, *args
)
22 self
.b_icon
.setIcon("inode-directory")
23 self
.b_icon
.setIconType(KIconLoader
.Desktop
, KIconLoader
.Place
)
26 self
.connect(self
.b_icon
, SIGNAL("iconChanged(QString)"), self
.changedIcon
)
27 self
.connect(self
.r_newp
, SIGNAL("clicked(bool)"), self
.enableNext
)
28 self
.connect(self
.r_loadp
, SIGNAL("clicked()"), self
.checkUrl_Load
)
29 self
.connect(self
.url_newp
, SIGNAL("urlSelected(KUrl)"), self
.checkForNewProjectFolder
)
30 self
.connect(self
.url_loadp
, SIGNAL("urlSelected(KUrl)"), self
.checkForProjectFile
)
31 self
.connect(self
.url_newp
, SIGNAL("textChanged(QString)"), self
.checkUrl_New
)
32 self
.connect(self
.url_loadp
, SIGNAL("textChanged(QString)"), self
.checkUrl_Load
)
33 self
.connect(self
, SIGNAL("currentIdChanged(int)"), self
.changedPage
)
34 self
.connect(self
, SIGNAL("accepted()"), self
.Accept
)
36 def changedIcon(self
, icon
):
39 def changedPage(self
, pageN
):
41 if (self
.r_loadp
.isChecked()):
43 elif (self
.r_ladip
.isChecked()):
48 def checkForNewProjectFolder(self
, pUrl
):
49 if not pUrl
.isLocalFile():
50 KMessageBox
.error(self
, i18n("The Selected folder cannot be used for a Klaudia project!"), i18n("Error"))
52 def checkForProjectFile(self
, pUrl
):
53 if not pUrl
.isLocalFile():
54 KMessageBox
.error(self
, i18n("The Selected folder cannot be used for a Klaudia project!"), i18n("Error"))
56 if (not os
.path
.exists(pUrl
.toLocalFile()+"/project.klaudia")):
57 KMessageBox
.sorry(self
, i18n("The Selected folder does not contain a Klaudia project!"), i18n("Sorry"))
59 def checkUrl_New(self
, url
=""):
60 if not url
: url
= self
.url_newp
.text()
61 if (os
.path
.exists(url
)):
62 self
.enableFinish(True)
64 self
.enableFinish(False)
66 def checkUrl_Load(self
, url
=""):
67 if not url
: url
= self
.url_loadp
.text()
68 if (os
.path
.exists(url
+"/project.klaudia")):
71 self
.enableNext(False)
73 def enableNext(self
, check
):
74 self
.button(QWizard
.NextButton
).setEnabled(check
)
76 def enableFinish(self
, check
):
77 self
.button(QWizard
.FinishButton
).setEnabled(check
)
80 if (self
.r_ladip
.isChecked()):
81 if (not os
.path
.exists("/tmp/klaudia-temp-proj")):
82 os
.mkdir("/tmp/klaudia-temp-proj")
83 shared
.p_folder
= "/tmp/klaudia-temp-proj"
84 shared
.p_bpm
= "130.0"
85 shared
.p_time_start
= "00:00:00"
86 shared
.p_time_end
= "00:03:00"
87 shared
.p_name
= str(shared
.studioBus
.GetName())
89 shared
.p_composer
= ""
92 shared
.ladish_project_name
= str(shared
.studioBus
.GetName())
93 self
.createProjectFile()
94 elif (self
.r_loadp
.isChecked()):
95 url
= self
.url_loadp
.text()
97 if (os
.path
.exists(url
+"/.directory")):
98 iconF
= open(url
+"/.directory").read().split("Icon=")
100 icon
= iconF
[-1].split()[0]
103 shared
.p_folder
= str(self
.url_newp
.text())
104 shared
.p_bpm
= self
.spin_bpm
.text()
105 shared
.p_time_start
= "00:00:00"
106 shared
.p_time_end
= self
.time_total
.text()
107 shared
.p_name
= self
.line_name
.text()
108 shared
.p_author
= self
.line_author
.text()
109 shared
.p_composer
= self
.line_composer
.text()
110 shared
.p_track
= self
.spin_track
.text()
111 shared
.p_album
= self
.line_album
.text()
112 shared
.ladish_project_name
= "klaudia_"+str(randint(1, 99999))+" - "+str(self
.line_name
.text())
113 self
.createProjectFile()
114 shared
.controlBus
.NewStudio(str(ladish_project_name
))
115 shared
.jackBus
.StartServer()
116 shared
.studioBus
.Save()
119 def createProjectFile(self
):
120 url
= shared
.p_folder
121 filename
= QFile(url
+"/project.klaudia")
122 if not filename
.open(QIODevice
.WriteOnly
):
123 KMessageBox
.error(self
, i18n("Cannot write to selected directory - Permission Denied"), i18n("Error"))
126 #raise IOError, unicode(filename.errorString())
127 stream
= QTextStream(filename
)
128 stream
.setCodec("UTF-8")
129 stream
<< ("<?xml version='1.0' encoding='UTF-8'?>\n"
130 "<!DOCTYPE KLAUDIA>\n"
131 "<KLAUDIA VERSION='0.1'>\n"
134 " <Author>%s</Author>\n"
135 " <Composer>%s</Composer>\n"
136 " <Album>%s</Album>\n"
137 " <Track>%s</Track>\n"
139 " <Time-Start>%s</Time-Start>\n"
140 " <Time-End>%s</Time-End>\n"
143 " <Project-Name>%s</Project-Name>\n"
145 "</KLAUDIA>\n" % (shared
.p_name
, shared
.p_author
, shared
.p_composer
,
146 shared
.p_album
, shared
.p_track
, shared
.p_bpm
, shared
.p_time_start
, shared
.p_time_end
, shared
.ladish_project_name
))
147 iconfile
= open(url
+"/.directory", "w")
148 iconfile
.write("[Desktop Entry]\nIcon=%s\n" % str(self
.b_icon
.icon()))