/// <summary> /// Disconnect sim card from reader /// </summary> private void SimDisconnect() { GlobalObj.CloseConnection(); UpdateSimControls(false); mainwindow_Ui.LstSimContacts.Clear(); MainClass.QtWait(); }
/// <summary> /// Updates during sim contacts reading /// </summary> private void ReadingUpdate() { PBar.SetValue(GlobalObjUI.SimADNPosition); mainwindow_Ui.StatusBar.ShowMessage(GlobalObjUI.LMan.GetString("readcontact") + GlobalObjUI.SimADNPosition.ToString("d3")); MainClass.QtWait(); if (GlobalObjUI.SimADNStatus == 3 && !isEnd) { isEnd = true; // End with errors MainClass.ShowMessage(this, "ERROR", GlobalObjUI.SimADNError, MainClass.MessageType.Error); // Update gui widgets properties ScanSimAfter(); // update gui widgets with results UpdateSimControls(false); } if (GlobalObjUI.SimADNStatus == 2 && !isEnd) { isEnd = true; // Extract contacts from records retStr = GlobalObjUI.FromRecordsToContacts(); if (retStr != "") { // error detected MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error); // Update gui widgets properties ScanSimAfter(); // update gui widgets with results UpdateSimControls(false); } else { // update ListView List <string> rowContent = null; foreach (Contact cnt in GlobalObjUI.SimContacts.SimContacts) { rowContent = new List <string>(); rowContent.Add(" "); rowContent.Add(cnt.Description); rowContent.Add(cnt.PhoneNumber); new QTreeWidgetItem(mainwindow_Ui.LstSimContacts, rowContent); } // Update gui widgets properties ScanSimAfter(); // update gui widgets with results UpdateSimControls(true); } } }
/// <summary> /// Perform sim card connection and contacts read. /// </summary> private void SimConnect() { MainClass.QtWait(); if (GlobalObj.IsPowered) { // Disconnect card if needed GlobalObj.CloseConnection(); } // Connect to smartcard retStr = GlobalObj.AnswerToReset(ref ATR); // check for error if (retStr != "") { // error on answer to reset log.Error("MainWindowClass::SimConnect: " + retStr); MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error); return; } // read sim contacts and fill list retStr = GlobalObjUI.SelectSimContactsList(); // check for error if (retStr != "") { if (retStr == GlobalObjUI.LMan.GetString("needpindisable")) { // Pin1 enabled MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error); EnableSimPinControl(); return; } else { // error on reading contacts list GlobalObj.CloseConnection(); MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error); return; } } ScanSimBefore(); mainwindow_Ui.LstSimContacts.Clear(); // Reset status values GlobalObjUI.SimADNStatus = 1; GlobalObjUI.SimADNPosition = 0; GlobalObjUI.SimADNError = ""; // Start thread for reading process isEnd = false; isReading = true; simThread = new System.Threading.Thread(new System.Threading.ThreadStart(GlobalObjUI.ReadSimContactsList)); simThread.Start(); }
/// <summary> /// Set gui widgets after sim scan /// </summary> private void ScanSimAfter() { PBar.SetVisible(false); mainwindow_Ui.MainMenu.Enabled = true; mainwindow_Ui.TopToolBar.Enabled = true; mainwindow_Ui.FrameSim.Enabled = true; mainwindow_Ui.FrameFile.Enabled = true; MainClass.QtWait(); }
/// <summary> /// Set gui widgets before sim scan /// </summary> private void ScanSimBefore() { // Setup ProgressBar PBar.SetMinimum(0); PBar.SetMaximum(GlobalObjUI.SimADNRecordCount); PBar.SetValue(0); PBar.SetVisible(true); mainwindow_Ui.MainMenu.Enabled = false; mainwindow_Ui.TopToolBar.Enabled = false; mainwindow_Ui.FrameSim.Enabled = false; mainwindow_Ui.FrameFile.Enabled = false; MainClass.QtWait(); }
/// <summary> /// Updates during sim contacts writing /// </summary> private void WritingUpdate() { PBar.Value = GlobalObjUI.SimADNPosition; mainwindow_Ui.StatusBar.ShowMessage(GlobalObjUI.LMan.GetString("writecontact") + GlobalObjUI.SimADNPosition.ToString("d3")); MainClass.QtWait(); if (GlobalObjUI.SimADNStatus == 3 && !isEnd) { // End with errors isEnd = true; MainClass.ShowMessage(this, "ERROR", GlobalObjUI.SimADNError, MainClass.MessageType.Error); SimConnect(); return; } // check for sim write ended if (GlobalObjUI.SimADNStatus == 2 && !isEnd) { isEnd = true; SimConnect(); } }
/// <summary> /// Open contacts file. /// </summary> private void OpenContactsFile() { GlobalObjUI.ContactsFilePath = ""; // New dialog for select contacts file string selectedFile = QFileDialog.GetOpenFileName(this, GlobalObjUI.LMan.GetString("openfileact"), null, "monosim files *.monosim (*.monosim)"); if (string.IsNullOrEmpty(selectedFile)) { return; } // path of a right file returned GlobalObjUI.ContactsFilePath = selectedFile; // Update gui UpdateFileControls(false); // Clear ListView mainwindow_Ui.LstFileContacts.Clear(); MainClass.QtWait(); try { GlobalObjUI.FileContacts = new Contacts(); StreamReader sr = new StreamReader(GlobalObjUI.ContactsFilePath); string descRow = sr.ReadLine(); string phoneRow = ""; while (!sr.EndOfStream) { phoneRow = sr.ReadLine(); // check for right values if (descRow.Trim() != "" && phoneRow.Trim() != "") { GlobalObjUI.FileContacts.SimContacts.Add(new Contact(descRow, phoneRow)); } // read new contact description descRow = sr.ReadLine(); } sr.Close(); sr.Dispose(); sr = null; } catch (Exception Ex) { log.Error("MainWindowClass::OpenContactsFile: " + Ex.Message + "\r\n" + Ex.StackTrace); MainClass.ShowMessage(this, "ERROR", Ex.Message, MainClass.MessageType.Error); return; } // loop to append data readed from file List <string> rowContent = null; foreach (Contact cnt in GlobalObjUI.FileContacts.SimContacts) { rowContent = new List <string>(); rowContent.Add(" "); rowContent.Add(cnt.Description); rowContent.Add(cnt.PhoneNumber); new QTreeWidgetItem(mainwindow_Ui.LstFileContacts, rowContent); } UpdateFileControls(true); }