20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
|
25 #include "hbinputcommondialogs.h" |
|
26 |
25 #include <QDir> |
27 #include <QDir> |
26 #include <QtAlgorithms> |
28 #include <QtAlgorithms> |
27 |
29 |
28 #include <hbinputdef.h> |
30 #include <hbinputdef.h> |
29 #include <hbselectiondialog.h> |
31 #include <hbselectiondialog.h> |
30 #include <hblistwidgetitem.h> |
32 #include <hblistwidgetitem.h> |
31 #include <hbinpututils.h> |
33 #include <hbinpututils.h> |
32 #include <hbinputsettingproxy.h> |
34 #include <hbinputsettingproxy.h> |
33 #include <hbinputmethod.h> |
35 #include <hbinputmethod.h> |
34 |
36 #include <hbinputregioncollector_p.h> |
35 #include "hbinputcommondialogs.h" |
|
36 |
37 |
37 /// @cond |
38 /// @cond |
38 |
39 |
39 bool caseInsensitiveLessThanForHbInputLanguage(const HbInputLanguage &s1, const HbInputLanguage &s2) |
40 bool caseInsensitiveLessThanForHbInputLanguage(const HbInputLanguage &s1, const HbInputLanguage &s2) |
40 { |
41 { |
49 /*! |
50 /*! |
50 Displays language selection dialog and returns selected language. |
51 Displays language selection dialog and returns selected language. |
51 */ |
52 */ |
52 HbInputLanguage HbInputCommonDialogs::showLanguageSelectionDialog(QLocale::Language selectedLanguage, const QList<HbInputLanguage> languageList) |
53 HbInputLanguage HbInputCommonDialogs::showLanguageSelectionDialog(QLocale::Language selectedLanguage, const QList<HbInputLanguage> languageList) |
53 { |
54 { |
54 HbSelectionDialog* langDialog = new HbSelectionDialog(); |
55 HbSelectionDialog *langDialog = new HbSelectionDialog(); |
55 langDialog->setObjectName("Language dialog"); |
56 langDialog->setObjectName("Language dialog"); |
56 |
57 |
57 #if QT_VERSION >= 0x040600 |
|
58 // Make sure the language dialog never steals focus. |
58 // Make sure the language dialog never steals focus. |
59 langDialog->setFlag(QGraphicsItem::ItemIsPanel, true); |
59 langDialog->setFlag(QGraphicsItem::ItemIsPanel, true); |
60 langDialog->setActive(false); |
60 langDialog->setActive(false); |
61 #endif |
|
62 |
61 |
63 HbInputSettingProxy* settings = HbInputSettingProxy::instance(); |
62 HbInputSettingProxy *settings = HbInputSettingProxy::instance(); |
64 HbInputLanguage currentLang = settings->globalInputLanguage(); |
63 HbInputLanguage currentLang = settings->globalInputLanguage(); |
65 QList<HbInputLanguage> languages; |
64 QList<HbInputLanguage> languages; |
66 if (languageList.count() == 0) { |
65 if (languageList.count() == 0) { |
67 HbInputUtils::listSupportedInputLanguages(languages); |
66 HbInputUtils::listSupportedInputLanguages(languages); |
68 } else { |
67 } else { |
69 languages=languageList; |
68 languages = languageList; |
70 } |
69 } |
71 |
70 |
72 qStableSort(languages.begin(), languages.end(), caseInsensitiveLessThanForHbInputLanguage); |
71 qStableSort(languages.begin(), languages.end(), caseInsensitiveLessThanForHbInputLanguage); |
73 QList<HbListWidgetItem*> listItems; |
72 QList<HbListWidgetItem *> listItems; |
74 HbListWidgetItem* item = 0; |
73 HbListWidgetItem *item = 0; |
75 foreach( HbInputLanguage language, languages ) { |
74 foreach(HbInputLanguage language, languages) { |
76 QString langName = language.localisedName(); |
75 QString langName = language.localisedName(); |
77 if (langName.length() == 0) { |
76 if (langName.length() == 0) { |
78 langName = QString("Unknown"); |
77 langName = QString("Unknown"); |
79 } |
78 } |
80 item = new HbListWidgetItem(); |
79 item = new HbListWidgetItem(); |
81 item->setText(langName); |
80 item->setText(langName); |
82 if (language == currentLang ) { |
81 if (language == currentLang) { |
83 QList<QVariant> selected; |
82 QList<QVariant> selected; |
84 selected.append(listItems.count()); |
83 selected.append(listItems.count()); |
85 langDialog->setSelectedItems(selected); |
84 langDialog->setSelectedItems(selected); |
86 } |
85 } |
87 if (language.language() == QLocale::Chinese) { |
86 if (language.language() == QLocale::Chinese) { |
95 langDialog->setWidgetItems(listItems, true); |
94 langDialog->setWidgetItems(listItems, true); |
96 langDialog->setSelectionMode(HbAbstractItemView::SingleSelection); |
95 langDialog->setSelectionMode(HbAbstractItemView::SingleSelection); |
97 langDialog->setDismissPolicy(HbPopup::NoDismiss); |
96 langDialog->setDismissPolicy(HbPopup::NoDismiss); |
98 langDialog->setModal(true); |
97 langDialog->setModal(true); |
99 //langDialog->exec(); TODO |
98 //langDialog->exec(); TODO |
|
99 HbInputRegionCollector::instance()->attach(langDialog); |
100 //TODO: needed to check from action which button was pressed (ok, cancel) |
100 //TODO: needed to check from action which button was pressed (ok, cancel) |
101 //HbAction* action = langDialog->exec(); |
101 //HbAction* action = langDialog->exec(); |
102 if (langDialog->selectedItems().count()) { |
102 if (langDialog->selectedItems().count()) { |
103 int selection = langDialog->selectedItems().at(0).toInt(); |
103 int selection = langDialog->selectedItems().at(0).toInt(); |
104 HbInputLanguage result; |
104 HbInputLanguage result; |
105 if(languages.at(selection).language() == QLocale::Chinese) { |
105 if (languages.at(selection).language() == QLocale::Chinese) { |
106 result = languages.at(selection); |
106 result = languages.at(selection); |
107 } else { |
107 } else { |
108 result = languages.at(selection).language(); |
108 result = languages.at(selection).language(); |
109 } |
109 } |
110 return result; |
110 return result; |
120 */ |
120 */ |
121 HbInputMethodDescriptor HbInputCommonDialogs::showCustomInputMethodSelectionDialog(const HbInputLanguage &language) |
121 HbInputMethodDescriptor HbInputCommonDialogs::showCustomInputMethodSelectionDialog(const HbInputLanguage &language) |
122 { |
122 { |
123 Q_UNUSED(language); |
123 Q_UNUSED(language); |
124 |
124 |
125 HbSelectionDialog* methodDialog = new HbSelectionDialog(); |
125 HbSelectionDialog *methodDialog = new HbSelectionDialog(); |
126 methodDialog->setObjectName("Input method dialog"); |
126 methodDialog->setObjectName("Input method dialog"); |
127 |
127 |
128 #if QT_VERSION >= 0x040600 |
|
129 // Make sure the language dialog never steals focus. |
128 // Make sure the language dialog never steals focus. |
130 methodDialog->setFlag(QGraphicsItem::ItemIsPanel, true); |
129 methodDialog->setFlag(QGraphicsItem::ItemIsPanel, true); |
131 methodDialog->setActive(false); |
130 methodDialog->setActive(false); |
132 #endif |
|
133 |
131 |
134 QList<HbInputMethodDescriptor> customList = HbInputMethod::listCustomInputMethods(); |
132 QList<HbInputMethodDescriptor> customList = HbInputMethod::listCustomInputMethods(); |
135 |
133 |
136 QList<HbListWidgetItem*> listItems; |
134 QList<HbListWidgetItem *> listItems; |
137 HbListWidgetItem* item = new HbListWidgetItem(); |
135 HbListWidgetItem *item = new HbListWidgetItem(); |
138 QString methodName("Default"); |
136 QString methodName("Default"); |
139 item->setText(methodName); |
137 item->setText(methodName); |
140 listItems.append(item); |
138 listItems.append(item); |
141 |
139 |
142 //for (int i=0; i<customList.dllName.count() ; i++) { |
140 //for (int i=0; i<customList.dllName.count() ; i++) { |
143 foreach (HbInputMethodDescriptor descriptor, customList) { |
141 foreach(const HbInputMethodDescriptor &descriptor, customList) { |
144 QString displayName = descriptor.displayName(); |
142 QString displayName = descriptor.displayName(); |
145 if (displayName.length() == 0) { |
143 if (displayName.length() == 0) { |
146 displayName = QString("Unknown"); |
144 displayName = QString("Unknown"); |
147 } |
145 } |
148 item = new HbListWidgetItem(); |
146 item = new HbListWidgetItem(); |
149 item->setText(displayName); |
147 item->setText(displayName); |
152 methodDialog->setWidgetItems(listItems, true); |
150 methodDialog->setWidgetItems(listItems, true); |
153 methodDialog->setSelectionMode(HbAbstractItemView::SingleSelection); |
151 methodDialog->setSelectionMode(HbAbstractItemView::SingleSelection); |
154 methodDialog->setDismissPolicy(HbPopup::NoDismiss); |
152 methodDialog->setDismissPolicy(HbPopup::NoDismiss); |
155 methodDialog->setModal(true); |
153 methodDialog->setModal(true); |
156 //methodDialog->exec(); TODO |
154 //methodDialog->exec(); TODO |
|
155 HbInputRegionCollector::instance()->attach(methodDialog); |
157 //TODO: needed to check from action which button was pressed (ok, cancel) |
156 //TODO: needed to check from action which button was pressed (ok, cancel) |
158 //HbAction* action = langDialog->exec(); |
157 //HbAction* action = langDialog->exec(); |
159 |
158 |
160 HbInputMethodDescriptor result; |
159 HbInputMethodDescriptor result; |
161 if (methodDialog->selectedItems().count()) { |
160 if (methodDialog->selectedItems().count()) { |
162 int selection = methodDialog->selectedItems().first().toInt(); |
161 int selection = methodDialog->selectedItems().first().toInt(); |
163 if (selection == 0) { |
162 if (selection == 0) { |
164 result.setDefault(); |
163 result.setDefault(); |
165 } else { |
164 } else { |
166 result = customList[selection-1]; |
165 result = customList[selection-1]; |
167 } |
166 } |
168 } |
167 } |
169 |
168 |
170 return result; |
169 return result; |
171 } |
170 } |