コード例 #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(MainWindow, "ERROR", Ex.Message, MessageType.Error);
                return;
            }

            MainClass.ShowMessage(MainWindow, "INFO", GlobalObjUI.LMan.GetString("filesaved"), MessageType.Info);
        }
コード例 #2
0
        private void SaveContactsSim()
        {
            // check for contacts description chars len
            string retCheck = GlobalObjUI.CheckAlphaCharsLen(GlobalObjUI.SimContacts);

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

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

            int retMode = swmdc.Show();

            if (retMode < 0)
            {
                // 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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Perform sim card connection and contacts read.
        /// </summary>
        private void SimConnect()
        {
            MainClass.GtkWait();

            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(MainWindow, "ERROR", retStr, 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(MainWindow, "ERROR", retStr, MessageType.Error);
                    EnableSimPinControl();
                    return;
                }
                else
                {
                    // error on reading contacts list
                    GlobalObj.CloseConnection();
                    MainClass.ShowMessage(MainWindow, "ERROR", retStr, MessageType.Error);
                    return;
                }
            }

            ScanSimBefore();
            lstSimContacts.Clear();

            // Reset status values
            GlobalObjUI.SimADNStatus   = 1;
            GlobalObjUI.SimADNPosition = 0;
            GlobalObjUI.SimADNError    = "";

            // Start thread for reading process
            notify    = new ThreadNotify(new ReadyEvent(ReadingUpdate));
            simThread = new System.Threading.Thread(new System.Threading.ThreadStart(GlobalObjUI.ReadSimContactsList));
            simThread.Start();
        }
コード例 #4
0
        /// <summary>
        /// Show Dialog to change Pin1 status
        /// </summary>
        public string Show()
        {
            int    respType = -1;
            string pin1 = "", pin1check = "";
            int    retNumber = 0;

            while (1 == 1)
            {
                SetupDialog();
                respType  = ChangePinStatusDialog.Run();
                pin1      = TxtPin1.Text.Trim();
                pin1check = TxtPin1check.Text.Trim();
                ChangePinStatusDialog.Destroy();

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

                // check data entry
                if (pin1 == "" || pin1check == "")
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin, "ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MessageType.Warning);
                }
                else if (pin1.Trim() != pin1check.Trim())
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin, "ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk1"),
                                          MessageType.Warning);
                }
                else if (pin1.Trim().Length != 4)
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin, "ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MessageType.Warning);
                }
                else if (!int.TryParse(pin1.Trim(), out retNumber))
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin, "ERROR",
                                          GlobalObjUI.LMan.GetString("pinsimchk2"),
                                          MessageType.Warning);
                }
                else
                {
                    // Data are correct
                    return(GetHexFromPin(pin1));
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Updates during sim contacts reading
        /// </summary>
        private void ReadingUpdate()
        {
            PBar.Adjustment.Value = (double)GlobalObjUI.SimADNPosition;
            StatusBar.Push(1, GlobalObjUI.LMan.GetString("readcontact") +
                           GlobalObjUI.SimADNPosition.ToString("d3"));
            MainClass.GtkWait();


            if (GlobalObjUI.SimADNStatus == 3)
            {
                // End with errors
                MainClass.ShowMessage(MainWindow, "ERROR", GlobalObjUI.SimADNError, MessageType.Error);

                // Update gui widgets properties
                ScanSimAfter();

                // update gui widgets with results
                UpdateSimControls(false);
            }

            if (GlobalObjUI.SimADNStatus == 2)
            {
                // Extract contacts from records
                retStr = GlobalObjUI.FromRecordsToContacts();

                if (retStr != "")
                {
                    // error detected
                    MainClass.ShowMessage(MainWindow, "ERROR", retStr, MessageType.Error);

                    // Update gui widgets properties
                    ScanSimAfter();

                    // update gui widgets with results
                    UpdateSimControls(false);
                }
                else
                {
                    // update ListView
                    foreach (Contact cnt in GlobalObjUI.SimContacts.SimContacts)
                    {
                        lstSimContacts.AppendValues(new string[] { cnt.Description, cnt.PhoneNumber });
                    }

                    // Update gui widgets properties
                    ScanSimAfter();

                    // update gui widgets with results
                    UpdateSimControls(true);
                }
            }
        }
コード例 #6
0
        private void SimChangePin()
        {
            // check for Pin1 check attempts
            if (GlobalObjUI.SimPin1Attempts == 1)
            {
                // Pin1 one attempt
                MainClass.ShowMessage(MainWindow, GlobalObjUI.LMan.GetString("pinsimact"),
                                      GlobalObjUI.LMan.GetString("pinsimchk3"), MessageType.Warning);
                return;
            }
            else if (GlobalObjUI.SimPin1Attempts == 0)
            {
                // Pin1 no more attempt
                MainClass.ShowMessage(MainWindow, GlobalObjUI.LMan.GetString("pinsimact"),
                                      GlobalObjUI.LMan.GetString("pinsimchk4"), MessageType.Warning);
                return;
            }

            // Change Pin1 dialog
            ChangePinStatusDialogClass cpsdc = new ChangePinStatusDialogClass(MainWindow);
            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(MainWindow, GlobalObjUI.LMan.GetString("pinsimact"),
                                      retStr, MessageType.Error);
                return;
            }

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

            // Force sim disconnect
            SimDisconnect();
        }
コード例 #7
0
        /// <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  = NewContactDialog.Run();
                txtDesc   = TxtDesc.Text.Trim();
                txtNumber = TxtNumber.Text.Trim();
                NewContactDialog.Destroy();

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

                // check data entry
                if (txtDesc == "" || txtNumber == "")
                {
                    // send warning message
                    MainClass.ShowMessage(mainWin, "ERROR",
                                          GlobalObjUI.LMan.GetString("fieldsreq"),
                                          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"),
                                          MessageType.Warning);
                }
                else
                {
                    // Data are correct
                    Contact cnt = new Contact(txtDesc, txtNumber);
                    return(cnt);
                }
            }
        }
コード例 #8
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(MainWindow, "ERROR",
                                      GlobalObjUI.LMan.GetString("nosimspace"), MessageType.Error);
                return;
            }

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

            SimUpdate(contacts, isAppend);
        }
コード例 #9
0
        /// <summary>
        /// Updates during sim contacts writing
        /// </summary>
        private void WritingUpdate()
        {
            PBar.Adjustment.Value = (double)GlobalObjUI.SimADNPosition;
            StatusBar.Push(1, GlobalObjUI.LMan.GetString("writecontact") +
                           GlobalObjUI.SimADNPosition.ToString("d3"));
            MainClass.GtkWait();


            if (GlobalObjUI.SimADNStatus == 3)
            {
                // End with errors
                MainClass.ShowMessage(MainWindow, "ERROR", GlobalObjUI.SimADNError, MessageType.Error);
                //ScanSimAfter();
                SimConnect();
            }

            // check for sim write ended
            if (GlobalObjUI.SimADNStatus != 1)
            {
                // Update gui widgets properties
                //ScanSimAfter();
                SimConnect();
            }
        }
コード例 #10
0
        private void OpenContactsFile()
        {
            GlobalObjUI.ContactsFilePath = "";

            // New dialog for select contacts file
            Gtk.FileChooserDialog FileBox = new Gtk.FileChooserDialog(GlobalObjUI.LMan.GetString("openfileact"),
                                                                      MainWindow,
                                                                      FileChooserAction.Open,
                                                                      GlobalObjUI.LMan.GetString("cancellbl"), Gtk.ResponseType.Cancel,
                                                                      GlobalObjUI.LMan.GetString("openlbl"), Gtk.ResponseType.Accept);

            // Filter for using only monosim files
            Gtk.FileFilter myFilter = new Gtk.FileFilter();
            myFilter.AddPattern("*.monosim");
            myFilter.Name = "monosim files";
            FileBox.AddFilter(myFilter);

            // Manage result of dialog box
            FileBox.Icon = Gdk.Pixbuf.LoadFromResource("monosim.png");
            int retFileBox = FileBox.Run();

            if ((ResponseType)retFileBox == Gtk.ResponseType.Accept)
            {
                // path of a right file returned
                GlobalObjUI.ContactsFilePath = FileBox.Filename;

                FileBox.Destroy();
                FileBox.Dispose();
            }
            else
            {
                // nothing returned
                FileBox.Destroy();
                FileBox.Dispose();
                return;
            }


            // Update gui
            UpdateFileControls(false);
            lstFileContacts.Clear();
            MainClass.GtkWait();

            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(MainWindow, "ERROR", Ex.Message, MessageType.Error);
                return;
            }

            // loop to append data readed from file
            foreach (Contact cnt in GlobalObjUI.FileContacts.SimContacts)
            {
                lstFileContacts.AppendValues(new string[] { cnt.Description, cnt.PhoneNumber });
            }

            UpdateFileControls(true);
        }