2 # -*- coding: utf-8 -*-
7 import shared
, ui_wizard
8 from PyQt4
.QtCore
import QFile
, QIODevice
, QTextStream
, SIGNAL
9 from PyQt4
.QtGui
import QWizard
10 from PyKDE4
.kdecore
import i18n
11 from PyKDE4
.kdeui
import KIconLoader
, KMessageBox
13 # Connect to Jack DBus Service
14 bus
= dbus
.SessionBus()
15 jackBus
= bus
.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
17 # Check if Jack is started, start it if not
18 if not bool(jackBus
.IsStarted()):
19 print "Jack is not started, trying to starting it now..."
22 # Enable Jack for Klaudia
24 jack
.attach("Klaudia")
31 class WizardW(QWizard
, ui_wizard
.Ui_WizardW
):
32 def __init__(self
, *args
):
33 QWizard
.__init
__(self
, *args
)
36 # Check for Jack before anything else
38 print "Could not start Jack, quiting..."
39 KMessageBox
.error(self
, i18n("Could not auto-start Jack.\nPlease close all audio applications and start Jack.\nKlaudia will quit now."), i18n("Error"))
43 self
.b_icon
.setIcon("inode-directory")
44 self
.b_icon
.setIconType(KIconLoader
.Desktop
, KIconLoader
.Place
)
47 self
.connect(self
.b_icon
, SIGNAL("iconChanged(QString)"), self
.changedIcon
)
48 self
.connect(self
.r_newp
, SIGNAL("clicked(bool)"), self
.enableNext
)
49 self
.connect(self
.r_loadp
, SIGNAL("clicked()"), self
.checkUrl_Load
)
50 self
.connect(self
.url_newp
, SIGNAL("urlSelected(KUrl)"), self
.checkForNewProjectFolder
)
51 self
.connect(self
.url_loadp
, SIGNAL("urlSelected(KUrl)"), self
.checkForProjectFile
)
52 self
.connect(self
.url_newp
, SIGNAL("textChanged(QString)"), self
.checkUrl_New
)
53 self
.connect(self
.url_loadp
, SIGNAL("textChanged(QString)"), self
.checkUrl_Load
)
54 self
.connect(self
, SIGNAL("currentIdChanged(int)"), self
.changedPage
)
55 self
.connect(self
, SIGNAL("accepted()"), self
.Accept
)
57 def changedIcon(self
, icon
):
60 def changedPage(self
, pageN
):
62 if (self
.r_loadp
.isChecked()):
67 def checkForNewProjectFolder(self
, pUrl
):
68 if not pUrl
.isLocalFile():
69 KMessageBox
.error(self
, i18n("The Selected folder cannot be used for a Klaudia project!"), i18n("Error"))
71 def checkForProjectFile(self
, pUrl
):
72 if not pUrl
.isLocalFile():
73 KMessageBox
.error(self
, i18n("The Selected folder cannot be used for a Klaudia project!"), i18n("Error"))
75 if (not os
.path
.exists(pUrl
.toLocalFile()+"/project.klaudia")):
76 KMessageBox
.sorry(self
, i18n("The Selected folder does not contain a Klaudia project!"), i18n("Sorry"))
78 def checkUrl_New(self
, url
=""):
79 if not url
: url
= self
.url_newp
.text()
80 if (os
.path
.exists(url
)):
81 self
.enableFinish(True)
83 self
.enableFinish(False)
85 def checkUrl_Load(self
, url
=""):
86 if not url
: url
= self
.url_loadp
.text()
87 if (os
.path
.exists(url
+"/project.klaudia")):
90 self
.enableNext(False)
92 def enableNext(self
, check
):
93 self
.button(QWizard
.NextButton
).setEnabled(check
)
95 def enableFinish(self
, check
):
96 self
.button(QWizard
.FinishButton
).setEnabled(check
)
99 if (self
.r_loadp
.isChecked()):
100 url
= self
.url_loadp
.text()
101 shared
.p_folder
= url
102 shared
.setIconFromFolder(url
)
104 url
= self
.url_newp
.text()
105 shared
.p_folder
= url
106 filename
= QFile(url
+"/project.klaudia")
107 if not filename
.open(QIODevice
.WriteOnly
):
108 KMessageBox
.error(self
, i18n("Cannot write to selected directory - Permission Denied"), i18n("Error"))
110 #raise IOError, unicode(filename.errorString())
111 stream
= QTextStream(filename
)
112 stream
.setCodec("UTF-8")
113 stream
<< ("<?xml version='1.0' encoding='UTF-8'?>\n"
114 "<!DOCTYPE KLAUDIA>\n"
115 "<KLAUDIA VERSION='0.2'>\n"
118 " <Author>%s</Author>\n"
119 " <Composer>%s</Composer>\n"
120 " <Album>%s</Album>\n"
121 " <Track>%s</Track>\n"
123 " <Time-Start>00:00:00</Time-Start>\n"
124 " <Time-End>%s</Time-End>\n"
126 "</KLAUDIA>\n" % (self
.line_name
.text(), self
.line_author
.text(), self
.line_composer
.text(),
127 self
.line_album
.text(), self
.spin_track
.text(), self
.spin_bpm
.text(), self
.time_total
.text()))
128 iconfile
= open(url
+"/.directory", "w")
129 iconfile
.write("[Desktop Entry]\nIcon=%s" % str(self
.b_icon
.icon()))