Example #1
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);
        }