Beispiel #1
0
        /// <summary>
        /// Write contacts on file
        /// </summary>
        private void WriteContactsOnFile(string filePath, List <Contact> contacts)
        {
            try
            {
                // save contacts
                StreamWriter sw = new StreamWriter(filePath, false);

                foreach (Contact cnt in contacts)
                {
                    sw.WriteLine(cnt.Description);
                    sw.WriteLine(cnt.PhoneNumber);
                }

                sw.Close();
                sw.Dispose();
                sw = null;
            }
            catch (Exception Ex)
            {
                log.Error("MainWindowClass::WriteContactsOnFile: " + Ex.Message + "\r\n" + Ex.StackTrace);
                MainClass.ShowMessage(this, "ERROR", Ex.Message, MainClass.MessageType.Error);
                return;
            }

            MainClass.ShowMessage(this, "INFO", GlobalObjUI.LMan.GetString("filesaved"), MainClass.MessageType.Info);
        }
Beispiel #2
0
        /// <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);
                }
            }
        }
Beispiel #3
0
        /// <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>
        /// Show Dialog to change Pin1 status
        /// </summary>
        public string Show()
        {
            int    respType = 0;
            string pin1 = "",pin1check = "";
            int    retNumber = 0;

            while (1 == 1)
            {
                SetupDialog();
                respType = cpsDialogWidget.Exec();

                pin1      = cpsDialogWidget.Pin1;
                pin1check = cpsDialogWidget.Pin1check;
                cpsDialogWidget.Close();
                cpsDialogWidget.Dispose();

                if (respType != 0x01)
                {
                    // Cancel button pressed
                    return(null);
                }

                // check data entry
                if (pin1.Trim() == "" || pin1check.Trim() == "")
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MainClass.MessageType.Warning);
                }
                else if (pin1.Trim() != pin1check.Trim())
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk1"),
                                          MainClass.MessageType.Warning);
                }
                else if (pin1.Trim().Length != 4)
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MainClass.MessageType.Warning);
                }
                else if (!int.TryParse(pin1.Trim(),out retNumber))
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MainClass.MessageType.Warning);
                }
                else
                {
                    // Data are correct
                    return(GetHexFromPin(pin1));
                }
            }
        }
Beispiel #5
0
        private void SimChangePin()
        {
            // check for Pin1 check attempts
            if (GlobalObjUI.SimPin1Attempts == 1)
            {
                // Pin1 one attempt
                MainClass.ShowMessage(this, GlobalObjUI.LMan.GetString("pinsimact"),
                                      GlobalObjUI.LMan.GetString("pinsimchk3"), MainClass.MessageType.Warning);
                return;
            }
            else if (GlobalObjUI.SimPin1Attempts == 0)
            {
                // Pin1 no more attempt
                MainClass.ShowMessage(this, GlobalObjUI.LMan.GetString("pinsimact"),
                                      GlobalObjUI.LMan.GetString("pinsimchk4"), MainClass.MessageType.Warning);
                return;
            }

            // Change Pin1 dialog
            ChangePinStatusDialogClass cpsdc = new ChangePinStatusDialogClass(this);
            string pin1 = cpsdc.Show();

            if (pin1 == null)
            {
                // cancel button pressed
                return;
            }

            // Perform Pin1 status change
            retStr = GlobalObjUI.SetPinStatus(!GlobalObjUI.SimPin1Status, pin1);

            if (retStr != "")
            {
                // error detected during Pin1 status change
                MainClass.ShowMessage(this, GlobalObjUI.LMan.GetString("pinsimact"),
                                      retStr, MainClass.MessageType.Error);
                return;
            }

            // Pin1 status changed, reconnect sim now
            MainClass.ShowMessage(this, GlobalObjUI.LMan.GetString("pinsimact"),
                                  GlobalObjUI.LMan.GetString("pinsimdone"), MainClass.MessageType.Info);

            // Force sim disconnect
            SimDisconnect();
        }
        /// <summary>
        /// Show Dialog to add new contact and return it.
        /// </summary>
        public Contact Show()
        {
            int    respType = -1;
            string txtDesc = "",txtNumber = "";

            while (1 == 1)
            {
                SetupDialog();
                respType  = ncDialogWidget.Exec();
                txtDesc   = ncDialogWidget.Desc;
                txtNumber = ncDialogWidget.Number;
                ncDialogWidget.Close();
                ncDialogWidget.Dispose();

                if (respType != 1)
                {
                    // Cancel button pressed
                    return(null);
                }

                // check data entry
                if (txtDesc == "" || txtNumber == "")
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("fieldsreq"),
                                          MainClass.MessageType.Warning);
                }
                else if ((txtNumber.Length == 21) &&
                         (txtNumber.Substring(0,1) != "+"))
                {
                    // number max len is 20 digits
                    MainClass.ShowMessage(mainWin,"ERROR",
                                          GlobalObjUI.LMan.GetString("maxnumlen"),
                                          MainClass.MessageType.Warning);
                }
                else
                {
                    // Data are correct
                    Contact cnt = new Contact(txtDesc,txtNumber);
                    return(cnt);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Write passed contacts on sim card (append or override)
        /// </summary>
        private void WriteContactsOnSim(Contacts contacts, bool isAppend)
        {
            // check for space on sim
            if (!isAppend && (contacts.SimContacts.Count > GlobalObjUI.SimADNRecordCount))
            {
                // No enough space on sim
                MainClass.ShowMessage(this, "ERROR",
                                      GlobalObjUI.LMan.GetString("nosimspace"), MainClass.MessageType.Error);
                return;
            }

            if (isAppend && (contacts.SimContacts.Count > (GlobalObjUI.SimADNRecordCount -
                                                           GlobalObjUI.SimADNRecordNoEmpty)))
            {
                // No enough space on sim
                MainClass.ShowMessage(this, "ERROR",
                                      GlobalObjUI.LMan.GetString("nosimspace"), MainClass.MessageType.Error);
                return;
            }

            SimUpdate(contacts, isAppend);
        }
Beispiel #8
0
        private void SaveContactsSim()
        {
            // check for contacts description chars len
            string retCheck = GlobalObjUI.CheckAlphaCharsLen(GlobalObjUI.SimContacts);

            if (retCheck != "")
            {
                MainClass.ShowMessage(this, "ERROR",
                                      GlobalObjUI.LMan.GetString("maxlenexceeded")
                                      .Replace("'description'", "'<b>" + retCheck + "</b>'")
                                      + "<b>" + GlobalObjUI.SimADNMaxAlphaChars.ToString() + "</b>",
                                      MainClass.MessageType.Warning);

                return;
            }

            SelectWriteModeDialogClass swmdc =
                new SelectWriteModeDialogClass(GlobalObjUI.LMan.GetString("savesimact"));

            int retMode = swmdc.Show();

            if (retMode < 1)
            {
                // cancel button pressed
                return;
            }

            log.Debug("MainWindowClass::SaveContactsSim: SELECTED SIM WRITE MODE: " + retMode.ToString());
            if (retMode == 1)
            {
                WriteContactsOnSim(GlobalObjUI.SimContacts, true);
            }
            else
            {
                WriteContactsOnSim(GlobalObjUI.SimContacts, false);
            }
        }
Beispiel #9
0
        /// <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();
            }
        }
Beispiel #10
0
        /// <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);
        }