OSDN Git Service

Version 0.5
[fontmanager/fontmanager.git] / qml / fontmanager / MainPage.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 com.nokia.extras 1.0
42 import 'UIConstants.js' as UI
43
44 import "HelpDialog.js" as HelpHelper
45
46 Page {
47     id: mainPage
48     tools: mainTools
49
50     property bool disableTools: false
51
52     property bool showHelp: false
53     property string helpMessage: qsTr(
54                                      "<h1>How to use</h1>" +
55                                      "<hr/>" +
56                                      "<h2>Toolbar</h2>" +
57                                      "<p><img src=\"image://theme/icon-m-toolbar-add\">: Install font.  Please copy font file(s) to this device in advance.  Currently *.ttf and *.ttc are supported.</p>" +
58                                      "<p><img src=\"image://theme/icon-m-toolbar-settings\">: Configure fonts(expert).  You can assign/unassign any fonts to Serif/Sans Serif/Monospace/System.</p>" +
59                                      "<hr/>" +
60                                      "<h2>Menu(<img src=\"image://theme/icon-m-toolbar-view-menu\">)</h2>" +
61                                      "<p><b>Create Recommended Settings</b>: Create recommended settings.  <i>Normal</i> priority is given to user installed font(s).  System fonts have <i>Higher</i> priority.  System CJK fonts conflicts your installed fonts have <i>Lower</i> priority.</p>" +
62                                      "<p><b>Backup Config</b>: Save current fonts config into ~/MyDocs/Documents</p>" +
63                                      "<p><b>Restore Config</b>: Restore fonts config from backuped file</p>"
64                                      )
65
66     Connections {
67         target: controller
68         onClearInstalledFontList: {
69             installedFontList.clear()
70         }
71         onAppendInstalledFont: {
72             installedFontList.append({ "title": family, "subtitle": fullname })
73         }
74     }
75
76     ListModel {
77         id: installedFontList
78     }
79
80     PageHeader {
81         id: pageHeader
82         anchors.top: parent.top
83         anchors.left: parent.left
84         anchors.right: parent.right
85         enabled: !disableTools
86         text: qsTr("Installed Fonts")
87     }
88
89     Item {
90         id: contents
91         anchors.top: pageHeader.bottom
92         anchors.bottom: parent.bottom
93         anchors.left: parent.left
94         anchors.right: parent.right
95         anchors.margins: UI.DEFAULT_MARGIN / 2
96         clip: true
97
98         ListView {
99             id: installedFontListView
100             anchors.fill: parent
101             enabled: !disableTools
102             opacity: enabled ? 1.0 : 0.5
103
104             model: installedFontList
105
106             delegate: ListDelegate {
107                 onClicked: {
108                     if (mainMenu.status !== DialogStatus.Closed)
109                         mainMenu.close()
110                     var component = Qt.createComponent("InstalledFontInfoPage.qml")
111                     if (component.status === Component.Error)
112                         console.log("Error: " + component.errorString())
113                     pageStack.push(component, { "fontInfo": controller.fontInfo(title, subtitle) } );
114                 }
115             }
116
117         }
118
119         Flickable {
120             id: helpView
121             visible: false
122             anchors.fill: parent
123             contentHeight: helpText.paintedHeight
124             Text {
125                 id: helpText
126                 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
127                 width: parent.width
128                 text: helpMessage
129                 font.pixelSize: UI.FONT_DEFAULT
130                 color: "black"
131                 horizontalAlignment: Text.AlignLeft
132             }
133         }
134
135         ScrollDecorator {
136             id: scrollDecorator
137             flickableItem: installedFontListView
138         }
139
140
141     }
142
143     BusyIndicator {
144         id: busyIndicator
145         anchors.centerIn: parent
146         platformStyle: BusyIndicatorStyle { size: "large" }
147         running: mainPage.state == "busy"
148         visible: running
149     }
150
151     ToolBarLayout {
152         id: mainTools
153         visible: true
154         enabled: !disableTools
155         opacity: enabled ? 1.0 : 0.5
156         ToolIcon {
157             platformIconId: "toolbar-add"
158             onClicked: {
159                 if (mainMenu.status !== DialogStatus.Closed)
160                     mainMenu.close()
161                 pageStack.push(fontSelectionPage)
162             }
163         }
164         ToolIcon {
165             platformIconId: "toolbar-settings"
166             onClicked: {
167                 if (mainMenu.status !== DialogStatus.Closed)
168                     mainMenu.close()
169                 var component = Qt.createComponent("EditFontsConfPage.qml")
170                 if (component.status === Component.Error)
171                     console.log("Error: " + component.errorString())
172                 pageStack.push(component)
173             }
174         }
175         ToolIcon {
176             platformIconId: "toolbar-view-menu"
177             anchors.right: (parent === undefined) ? undefined : parent.right
178             onClicked: {
179                 if (mainMenu.status === DialogStatus.Closed)
180                     mainMenu.open()
181                 else
182                     mainMenu.close()
183             }
184         }
185     }
186
187     Menu {
188         id: mainMenu
189         visualParent: pageStack
190         MenuLayout {
191             MenuItem {
192                 id: createRecommendedSettingsItem
193                 text: qsTr("Create Recommended Settings");
194                 onClicked: {
195                     if (mainMenu.status !== DialogStatus.Closed)
196                         mainMenu.close()
197 //                    if (controller.installedFonts.length > 0) {
198 //                        console.log("Installed Fonts:" + controller.installedFonts)
199 //                    }
200                     if (controller.localFontsConfExists)
201                         openCreateConfirmDialog()
202                     else
203                         createRecommendedSettings()
204                 }
205             }
206             MenuItem {
207                 id: backupConfigItem
208                 text: qsTr("Backup Config")
209                 onClicked: backupConfig()
210                 enabled: !controller.isEmptyFontsConf
211             }
212             MenuItem {
213                 id: restoreConfigItem
214                 text: qsTr("Restore Config")
215                 onClicked: {
216                     var component = Qt.createComponent("RestoreFontsConfPage.qml")
217                     if (component.status === Component.Error)
218                         console.log("Error: " + component.errorString())
219                     pageStack.push(component)
220                 }
221             }
222             MenuItem {
223                 text: qsTr("About")
224                 onClicked: openAboutDialog()
225             }
226             MenuItem {
227                 text: qsTr("Help")
228                 onClicked: {
229                     showHelp = true
230                     HelpHelper.openHelpDialog(mainPage, contents, helpMessage, closeHelp)
231                 }
232             }
233         }
234     }
235
236     function openCreateConfirmDialog()
237     {
238         queryDialog.titleText = qsTr("Replace it?")
239         queryDialog.message = qsTr("Existing %1 will be replaced by recommended settings.  Are you sure?").arg(controller.localFontsConfPath)
240         queryDialog.acceptButtonText = qsTr("OK")
241         queryDialog.rejectButtonText = qsTr("Cancel")
242         queryDialog.accepted.connect(createRecommendedSettings)
243         queryDialog.open()
244     }
245
246     function createRecommendedSettings()
247     {
248         queryDialog.accepted.disconnect(createRecommendedSettings)
249         controller.createRecommendedSettings()
250     }
251
252     function openAboutDialog()
253     {
254         queryDialog.titleText = qsTr("Font Manager for N9")
255         queryDialog.message = qsTr("Version: %1\nAuthor: Takumi Asaki <takumi.asaki@gmail.com>\n\nApplication Icon is created by hirao").arg(controller.version)
256         queryDialog.acceptButtonText = qsTr("Close")
257         queryDialog.rejectButtonText = ""
258         queryDialog.open()
259     }
260
261     function closeHelp()
262     {
263         showHelp = false
264     }
265
266     function backupConfig()
267     {
268         var filepath = controller.defaultBackupFilename()
269         controller.backupConfig(filepath)
270     }
271
272     states: [
273         State {
274             name: "nofonts"
275             when: (installedFontListView.count == 0) && !controller.working && !showHelp
276             PropertyChanges {
277                 target: createRecommendedSettingsItem
278                 enabled: false
279             }
280 //            PropertyChanges {
281 //                target: installedFontListView
282 //                visible: false
283 //            }
284             PropertyChanges {
285                 target: helpView
286                 visible: true
287             }
288             PropertyChanges {
289                 target: scrollDecorator
290                 flickableItem: helpView
291             }
292             PropertyChanges {
293                 target: pageHeader
294                 text: qsTr("No Fonts Installed")
295             }
296         },
297         State {
298             name: "busy"
299             when: controller.working && !showHelp
300             PropertyChanges {
301                 target: mainPage
302                 disableTools: true
303             }
304         },
305         State {
306             name: "showHelp"
307             when: showHelp
308             PropertyChanges {
309                 target: mainPage
310                 disableTools: true
311             }
312         }
313
314     ]
315 }