qtmobility/examples/servicenotesmanager/declarative-sfw-notes/declarative-sfw-notes.qml
changeset 4 90517678cc4f
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 import Qt 4.6
       
     2 import QtSFW 1.0
       
     3 
       
     4 Rectangle {
       
     5     property int size: 0
       
     6     property int curr: 0
       
     7     property string search: ""
       
     8     property variant notesObject: notesService.serviceObject()
       
     9 
       
    10     id: mainWindow
       
    11     color: "lightgray"
       
    12     width: 220; height: 265
       
    13 
       
    14     SystemPalette { id: activePalette }
       
    15 
       
    16     Rectangle {
       
    17         id: datetimeArea
       
    18         width: 160; height: 20
       
    19         x: 30; y: 120
       
    20         color: "#FFFF7F"
       
    21     }
       
    22 
       
    23     Rectangle {
       
    24         id: noteArea
       
    25         width: 160; height: 110
       
    26         x: 30; y: 140
       
    27         color: "#FFFF7F"
       
    28     }
       
    29 
       
    30 
       
    31     Text {
       
    32         id: title
       
    33         text: "ToDoTool"
       
    34         font.pointSize: 24; font.family: "Nimbus Roman No9 L"; font.bold: true; font.italic:true 
       
    35         color: "blue"
       
    36         y: 5; anchors.horizontalCenter: mainWindow.horizontalCenter
       
    37     }
       
    38 
       
    39     Text {
       
    40         id: countLabel
       
    41         text: curr + "/" + size
       
    42         font.pointSize:10
       
    43         y: 90
       
    44         anchors.horizontalCenter: mainWindow.horizontalCenter
       
    45     }
       
    46 
       
    47     Text {
       
    48         id: datetimeLabel
       
    49         text: ""
       
    50         font.pointSize:10
       
    51         x: 30; y: 120
       
    52         anchors.right: datetimeArea.right
       
    53     }
       
    54 
       
    55     Text {
       
    56         id: noteLabel
       
    57         text: "Click + to add a new note"
       
    58         font.pointSize: 18; font.family: "Comic Sans MS"; font.italic:true
       
    59         horizontalAlignment: Text.AlignHCenter
       
    60         wrap: true
       
    61         width: noteArea.width
       
    62         anchors.verticalCenter: noteArea.verticalCenter
       
    63         anchors.horizontalCenter: title.horizontalCenter
       
    64     }
       
    65 
       
    66     Button {
       
    67         id: addButton
       
    68         image: "../icons/addIcon.png"
       
    69         width: 60; height: 30
       
    70         x: 20; y: 40
       
    71 
       
    72         onClicked: {
       
    73             addDialog.opacity = 1;
       
    74         }
       
    75     }
       
    76 
       
    77     Button {
       
    78         id: deleteButton
       
    79         image: "../icons/deleteIcon.png"
       
    80         width: 60; height: 30
       
    81         x: 80; y: 40
       
    82 
       
    83         onClicked: {
       
    84             deleteDialog.opacity = 1;
       
    85         }
       
    86     }
       
    87 
       
    88     Button {
       
    89         id: searchButton
       
    90         image: "../icons/searchIcon.png"
       
    91         width: 60; height: 30
       
    92         x: 140; y: 40
       
    93 
       
    94         onClicked: {
       
    95             searchDialog.opacity = 1;
       
    96         }
       
    97     }
       
    98 
       
    99     Button {
       
   100         id: nextButton
       
   101         image: "../icons/nextIcon.png"
       
   102         width: 40; height: 30
       
   103         x: 130; y: 80
       
   104 
       
   105         onClicked: { 
       
   106             if (curr < size) { 
       
   107                 curr++;
       
   108                 refreshNotes();
       
   109             }
       
   110         }
       
   111     }
       
   112 
       
   113     Button {
       
   114         id: prevButton
       
   115         image: "../icons/prevIcon.png"
       
   116         width: 40; height: 30
       
   117         x: 50; y: 80
       
   118 
       
   119         onClicked: {
       
   120             if (curr > 1) {
       
   121                 curr--;
       
   122                 refreshNotes();
       
   123             }
       
   124         }
       
   125     }
       
   126 
       
   127     DateTimeFormatter {
       
   128         id: myDateTime
       
   129         dateTime: "2000-01-01 00:00:00"
       
   130         dateTimeFormat: "yyyy-MM-dd hh:mm"
       
   131     }
       
   132 
       
   133     InputDialog {
       
   134         id: addDialog
       
   135         text: "Add a new note + alarm of format:\nnote#yyyy-mm-dd#hh:mm"
       
   136 
       
   137         onConfirmed: {
       
   138             var note = input.split("#");
       
   139 
       
   140             if (note.length == 3) {
       
   141                 var date = note[1].split("-");
       
   142                 var time = note[2].split(":");
       
   143 
       
   144                 if (date.length == 3 && time.length ==2) {
       
   145                     myDateTime.dateTime = note[1] + " " + note[2] + ":00";
       
   146                     notesObject.addNote(note[0], myDateTime.dateTime);
       
   147                 }
       
   148             } else {
       
   149                     myDateTime.dateTime = currentDateTime() + ":00";
       
   150                     notesObject.addNote(note[0], myDateTime.dateTime);
       
   151             }
       
   152 
       
   153             refreshNotes();
       
   154         }
       
   155     }
       
   156 
       
   157     InputDialog {
       
   158         id: searchDialog
       
   159         text: "Find a note:"
       
   160         size: 100
       
   161 
       
   162         onConfirmed: {
       
   163             search = input;
       
   164             curr = 1; 
       
   165             refreshNotes()
       
   166         }
       
   167     }
       
   168 
       
   169     Connections {
       
   170         target: notesObject
       
   171         
       
   172         onSoundAlarm: {
       
   173             alarmDialog.text = "ALERT SOUNDED!!!" + "\n\n" + 
       
   174                                formatDateTime(alarm) + "\n\n" + notesObject.alarmMessage;
       
   175             alarmDialog.opacity = 1;
       
   176         }
       
   177     }
       
   178 
       
   179     Dialog {
       
   180         id: deleteDialog
       
   181         text: "Confirm removing this note item?"
       
   182 
       
   183         onConfirmed: {
       
   184             var list = notesObject.noteSet;
       
   185             notesObject.removeNote(list[curr-1].index);
       
   186 
       
   187             if (curr > 1) { curr--; }
       
   188 
       
   189             refreshNotes();
       
   190         }
       
   191     }
       
   192 
       
   193     Dialog {
       
   194         id: alarmDialog
       
   195         text: "ALERT SOUNDED!!!"
       
   196         alert: true
       
   197     }
       
   198 
       
   199     Script {
       
   200         function refreshNotes()
       
   201         {
       
   202             notesObject.setSearch(search);
       
   203             var list = notesObject.noteSet;
       
   204             size = list.length;
       
   205            
       
   206             if (size < 1) curr = 0;
       
   207             else if (size > 0 && curr == 0) curr = 1;
       
   208           
       
   209             if (size > 0) {
       
   210                 noteLabel.text = list[curr-1].message;
       
   211                 datetimeLabel.text = formatDateTime(list[curr-1].alarm);
       
   212             } else {
       
   213                 noteLabel.text = "Click + to add a new note";
       
   214                 datetimeLabel.text = "";
       
   215             }
       
   216         }
       
   217 
       
   218         function formatDateTime(datetime)
       
   219         {
       
   220             var dt = new Date(datetime);
       
   221 
       
   222             var month = (dt.getMonth() + 1) + ""; 
       
   223             if (month.length == 1)  month = "0" + month;
       
   224 
       
   225             var date = dt.getDate() + ""; 
       
   226             if (date.length == 1)  date= "0" + date;
       
   227             
       
   228             var hour = dt.getHours() + ""; 
       
   229             if (hour.length == 1)  hour = "0" + hour;
       
   230             
       
   231             var mins = dt.getMinutes() + ""; 
       
   232             if (mins.length == 1)  mins = "0" + mins;
       
   233 
       
   234             return (dt.getFullYear() + "-" + month + "-" + date + " " + hour + ":" + mins);
       
   235         }
       
   236 
       
   237         function currentDateTime()
       
   238         {
       
   239             var dt = new Date();
       
   240 
       
   241             return formatDateTime(dt);
       
   242         }
       
   243     }
       
   244 
       
   245     Service {
       
   246         id: notesService
       
   247         interfaceName: "com.nokia.qt.examples.NotesManager"
       
   248         serviceName: "NotesManagerService"
       
   249         version: "1.2"
       
   250     }
       
   251 
       
   252     Component.onCompleted: {
       
   253         var list = notesObject.noteSet;
       
   254         if (list.length > 0) {curr = 1;}
       
   255         
       
   256         refreshNotes();
       
   257     }
       
   258 }