/monosim-qt/Src/Gui_Classes/MainWindowClass.Popup.cs

http://monosim.googlecode.com/ · C# · 227 lines · 133 code · 71 blank · 23 comment · 14 complexity · 37abbb11b42237a2317f0aecd56e3b0c MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Qyoto;
  5. using log4net;
  6. using comexbase;
  7. using monosimbase;
  8. namespace monosimqt
  9. {
  10. public partial class MainWindowClass
  11. {
  12. /// <summary>
  13. /// Add new contact action
  14. /// </summary>
  15. private void PopupFileAdd()
  16. {
  17. NewContactDialogClass ncdc = new NewContactDialogClass(this, 0, "", "");
  18. Contact newContact = ncdc.Show();
  19. if (newContact == null)
  20. {
  21. return;
  22. }
  23. // Add contact to file contacts
  24. GlobalObjUI.FileContacts.SimContacts.Add(newContact);
  25. List<string> contact = new List<string>();
  26. contact.Add(" ");
  27. contact.Add(newContact.Description);
  28. contact.Add(newContact.PhoneNumber);
  29. new QTreeWidgetItem(mainwindow_Ui.LstFileContacts, contact);
  30. }
  31. /// <summary>
  32. /// Add new contact action
  33. /// </summary>
  34. private void PopupSimAdd()
  35. {
  36. NewContactDialogClass ncdc = new NewContactDialogClass(this,
  37. GlobalObjUI.SimADNMaxAlphaChars, "", "");
  38. Contact newContact = ncdc.Show();
  39. if (newContact == null)
  40. {
  41. return;
  42. }
  43. // Add contact to file contacts
  44. GlobalObjUI.SimContacts.SimContacts.Add(newContact);
  45. List<string> contact = new List<string>();
  46. contact.Add(" ");
  47. contact.Add(newContact.Description);
  48. contact.Add(newContact.PhoneNumber);
  49. new QTreeWidgetItem(mainwindow_Ui.LstSimContacts, contact);
  50. }
  51. /// <summary>
  52. /// Del contact
  53. /// </summary>
  54. private void PopupFileDel()
  55. {
  56. if (mainwindow_Ui.LstFileContacts.SelectedItems().Count == 0)
  57. {
  58. // no selected rows
  59. return;
  60. }
  61. if (!DeleteContactQuestion())
  62. {
  63. return;
  64. }
  65. // loop for all selected items
  66. List<QTreeWidgetItem> selContacts = mainwindow_Ui.LstFileContacts.SelectedItems();
  67. int posw = -1;
  68. for (int qwidx=selContacts.Count-1; qwidx>=0; qwidx--)
  69. {
  70. posw = mainwindow_Ui.LstFileContacts.IndexOfTopLevelItem(selContacts[qwidx]);
  71. mainwindow_Ui.LstFileContacts.TakeTopLevelItem(posw);
  72. GlobalObjUI.FileContacts.SimContacts.RemoveAt(posw);
  73. }
  74. }
  75. /// <summary>
  76. /// Del contact
  77. /// </summary>
  78. private void PopupSimDel()
  79. {
  80. if (mainwindow_Ui.LstSimContacts.SelectedItems().Count == 0)
  81. {
  82. // no selected rows
  83. return;
  84. }
  85. if (!DeleteContactQuestion())
  86. {
  87. return;
  88. }
  89. // loop for all selected items
  90. List<QTreeWidgetItem> selContacts = mainwindow_Ui.LstSimContacts.SelectedItems();
  91. int posw = -1;
  92. for (int qwidx=selContacts.Count-1; qwidx>=0; qwidx--)
  93. {
  94. posw = mainwindow_Ui.LstSimContacts.IndexOfTopLevelItem(selContacts[qwidx]);
  95. mainwindow_Ui.LstSimContacts.TakeTopLevelItem(posw);
  96. GlobalObjUI.SimContacts.SimContacts.RemoveAt(posw);
  97. }
  98. }
  99. private void PopupFileMoveToSim()
  100. {
  101. // loop for all selected items
  102. List<QTreeWidgetItem> selContacts = mainwindow_Ui.LstFileContacts.SelectedItems();
  103. List<string> cntValues = new List<string>();
  104. foreach (QTreeWidgetItem fromw in selContacts)
  105. {
  106. cntValues = new List<string>();
  107. cntValues.Add(" ");
  108. cntValues.Add(fromw.Text(1));
  109. cntValues.Add(fromw.Text(2));
  110. new QTreeWidgetItem(mainwindow_Ui.LstSimContacts, cntValues);
  111. }
  112. foreach (QTreeWidgetItem qtwi in selContacts)
  113. {
  114. GlobalObjUI.SimContacts.SimContacts.Add(new Contact(qtwi.Text(1), qtwi.Text(2)));
  115. }
  116. }
  117. private void PopupSimMoveToFile()
  118. {
  119. // loop for all selected items
  120. List<QTreeWidgetItem> selContacts = mainwindow_Ui.LstSimContacts.SelectedItems();
  121. List<string> cntValues = new List<string>();
  122. foreach (QTreeWidgetItem fromw in selContacts)
  123. {
  124. cntValues = new List<string>();
  125. cntValues.Add(" ");
  126. cntValues.Add(fromw.Text(1));
  127. cntValues.Add(fromw.Text(2));
  128. new QTreeWidgetItem(mainwindow_Ui.LstFileContacts, cntValues);
  129. }
  130. foreach (QTreeWidgetItem qtwi in selContacts)
  131. {
  132. GlobalObjUI.FileContacts.SimContacts.Add(new Contact(qtwi.Text(1), qtwi.Text(2)));
  133. }
  134. }
  135. /// <summary>
  136. /// Are you sure dialog
  137. /// </summary>
  138. private bool DeleteContactQuestion()
  139. {
  140. QMessageBox mdlg = new QMessageBox(QMessageBox.Icon.Question,
  141. MainClass.AppNameVer + " - " + GlobalObjUI.LMan.GetString("delcontacts"),
  142. GlobalObjUI.LMan.GetString("suredelcontact"),
  143. (uint)QMessageBox.StandardButton.Yes |
  144. (uint)QMessageBox.StandardButton.No);
  145. int respType = mdlg.Exec();
  146. mdlg.Close();
  147. mdlg.Dispose();
  148. mdlg = null;
  149. if (respType == (uint)QMessageBox.StandardButton.Yes)
  150. {
  151. return true;
  152. }
  153. return false;
  154. }
  155. }
  156. }