OSDN Git Service

9f6b050875194904c98063402aeed34fd77e15e5
[fontmanager/fontmanager.git] / qml / fontmanager / main.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Takumi Asaki
4 ** All rights reserved.
5 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
6 **
7 ** This file is part of the fontmanager application.
8 **
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ****************************************************************************/
38
39 import QtQuick 1.1
40 import com.nokia.meego 1.0
41 import 'UIConstants.js' as UI
42
43 PageStackWindow {
44     id: appWindow
45
46     initialPage: mainPage
47
48     MainPage {
49         id: mainPage
50     }
51
52     property string filePath
53     property string alertMessage
54
55     Connections {
56         target: controller
57         onAlertDialog: {
58             alertMessage = message
59             openAlertDialog()
60         }
61
62         onInstallFinished: {
63             filePath = fontpath
64             openInstallFinishedDialog()
65         }
66
67         onUninstallFinished: {
68             filePath = fontpath
69             openUninstallFinishedDialog()
70         }
71
72         onBackupConfigFinished: {
73             filePath = filepath
74             openBackupConfigFinishedDialog()
75         }
76
77         onRestoreConfigFinished: {
78             filePath = filepath
79             openRestoreConfigFinishedDialog()
80         }
81
82         onClearInstallableFamilyListFor: {
83             installableFamilyListModel.clear()
84             installableFamilyListModel.family = family;
85         }
86
87         onAppendInstallableFamily: {
88             installableFamilyListModel.append( { "name": family, "enfamily": enfamily, "systemFont": systemFont } )
89         }
90     }
91
92     ListModel {
93         id: installableFamilyListModel
94         property string family
95     }
96
97     Component {
98         id: fontSelectionPage
99         FontSelectionPage {
100         }
101     }
102
103     function openAlertDialog()
104     {
105         queryDialog.statusChanged.disconnect(openAlertDialog)
106         if (queryDialog.status !== DialogStatus.Closed) {
107             queryDialog.statusChanged.connect(openAlertDialog)
108             return
109         }
110         queryDialog.titleText = qsTr("Alert")
111         queryDialog.message = alertMessage
112         queryDialog.acceptButtonText = qsTr("Close")
113         queryDialog.rejectButtonText = ""
114         queryDialog.open()
115     }
116
117     function openFinishedDialog()
118     {
119         queryDialog.acceptButtonText = qsTr("Close")
120         queryDialog.rejectButtonText = ""
121         queryDialog.accepted.connect(popToMainPage)
122         queryDialog.rejected.connect(popToMainPage)
123         queryDialog.open()
124     }
125
126     function openInstallFinishedDialog()
127     {
128         queryDialog.statusChanged.disconnect(openInstallFinishedDialog)
129         if (queryDialog.status !== DialogStatus.Closed) {
130             queryDialog.statusChanged.connect(openInstallFinishedDialog)
131             return
132         }
133         queryDialog.titleText = qsTr("Install finished")
134         queryDialog.message = qsTr("Font '%1' is installed successfully.").arg(filePath)
135         openFinishedDialog()
136     }
137
138     function openUninstallFinishedDialog()
139     {
140         queryDialog.statusChanged.disconnect(openUninstallFinishedDialog)
141         if (queryDialog.status !== DialogStatus.Closed) {
142             queryDialog.statusChanged.connect(openUninstallFinishedDialog)
143             return
144         }
145         queryDialog.titleText = qsTr("Uninstall finished")
146         queryDialog.message = qsTr("Font '%1' is uninstalled successfully.").arg(filePath)
147         openFinishedDialog()
148     }
149
150     function openBackupConfigFinishedDialog()
151     {
152         queryDialog.statusChanged.disconnect(openBackupConfigFinishedDialog)
153         if (queryDialog.status !== DialogStatus.Closed) {
154             queryDialog.statusChanged.connect(openBackupConfigFinishedDialog)
155             return
156         }
157         queryDialog.titleText = qsTr("Backup finished")
158         queryDialog.message = qsTr("Fonts Config is backuped as '%1' successfully.").arg(controller.path4display(filePath))
159         openFinishedDialog()
160     }
161
162     function openRestoreConfigFinishedDialog()
163     {
164         queryDialog.statusChanged.disconnect(openRestoreConfigFinishedDialog)
165         if (queryDialog.status !== DialogStatus.Closed) {
166             queryDialog.statusChanged.connect(openRestoreConfigFinishedDialog)
167             return
168         }
169         queryDialog.titleText = qsTr("Restore finished")
170         queryDialog.message = qsTr("Fonts Config is restored from '%1' successfully.").arg(controller.path4display(filePath))
171         openFinishedDialog()
172     }
173
174     function popToMainPage()
175     {
176         queryDialog.accepted.disconnect(popToMainPage)
177         queryDialog.rejected.disconnect(popToMainPage)
178         if (pageStack.currentPage !== mainPage)
179             pageStack.pop(mainPage)
180     }
181
182     QueryDialog {
183         id: queryDialog
184     }
185
186 }