From: <che...@us...> - 2007-04-08 17:34:46
|
Revision: 297 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=297&view=rev Author: chef_koch Date: 2007-04-08 10:34:44 -0700 (Sun, 08 Apr 2007) Log Message: ----------- import phonebook from FRITZ!Box Monitor is now possible Modified Paths: -------------- trunk/plugins/FritzBox/Caller.cs trunk/plugins/FritzBox/FritzBox.cs trunk/plugins/FritzBox/FritzBoxSetupFrom.cs trunk/plugins/FritzBox/FritzBoxSetupFrom.resx Modified: trunk/plugins/FritzBox/Caller.cs =================================================================== --- trunk/plugins/FritzBox/Caller.cs 2007-04-08 11:07:48 UTC (rev 296) +++ trunk/plugins/FritzBox/Caller.cs 2007-04-08 17:34:44 UTC (rev 297) @@ -31,17 +31,59 @@ { public class Caller { + string _id; + string _name; + bool _show; - public readonly string callerId; - public readonly string name; - public readonly bool show; - - public Caller(string CallerId, string Name, bool Show) + public Caller() { - this.callerId = CallerId; - this.name = Name; - this.show = Show; + this._id = ""; + this._name = ""; + this._show = false; } + public Caller(string id, string name, bool show) + { + this._id = id; + this._name = name; + this._show = show; + } + + public string ID + { + get + { + return _id; + } + set + { + _id = value; + } + } + + public string Name + { + get + { + return _name; + } + set + { + _name = value; + } + } + + public bool Show + { + get + { + return _show; + } + set + { + _show = value; + } + } + } } Modified: trunk/plugins/FritzBox/FritzBox.cs =================================================================== --- trunk/plugins/FritzBox/FritzBox.cs 2007-04-08 11:07:48 UTC (rev 296) +++ trunk/plugins/FritzBox/FritzBox.cs 2007-04-08 17:34:44 UTC (rev 297) @@ -56,8 +56,6 @@ private bool _fritzBoxDisabled = false; - public List<Caller> phonebook = new List<Caller>(); - // notify settings private int _timeout = -1; // autoclose the dialog after the timeout expired private bool _closeOnTimeout = false; @@ -84,6 +82,8 @@ public static bool _showUnknownCaller = true; public static bool _saveUnknownCaller = true; + public static List<Caller> phonebook = new List<Caller>(); + #endregion FritzBoxWatch FritzBoxWatch; @@ -155,38 +155,74 @@ Log.Info("FRITZ!Box: saveUnknownCaller = {0}", _saveUnknownCaller.ToString()); } } + + LoadPhonebook(); + } + private void SaveSettings() + { + if (_extensiveLogging) + Log.Info("FRITZ!Box: SaveSettings"); + + using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + xmlwriter.SetValue("fritzbox", "lastVersion", _version.Replace(".", string.Empty)); + } + + SavePhonebook(); + } + #endregion + + #region Phonebook + public static void LoadPhonebook() + { if ((_lastVersion < 0220) && (!File.Exists(Config.GetFile(Config.Dir.Config, "fritzbox.xml")))) + { UpdateTo0220(); - else - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) + return; + } + + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) + { + int countCaller = xmlreader.GetValueAsInt("phonebook", "count", 0); + + for (int i = 0; i < countCaller; i++) { - int countCaller = xmlreader.GetValueAsInt("phonebook", "count", 0); + Caller caller = new Caller(); - for (int i = 0; i < countCaller; i++) - { - string strCallerId = xmlreader.GetValueAsString("phonebook", string.Format("callerID{0}", i.ToString()), ""); - string strName = xmlreader.GetValueAsString("phonebook", string.Format("name{0}", i.ToString()), ""); - bool bShow = xmlreader.GetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), false); + caller.ID = xmlreader.GetValueAsString("phonebook", string.Format("callerID{0}", i.ToString()), ""); + caller.Name = xmlreader.GetValueAsString("phonebook", string.Format("name{0}", i.ToString()), ""); + caller.Show = xmlreader.GetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), false); - if (strCallerId == "") continue; - if (strCallerId == null) continue; - if (strName == "") continue; - if (strName == null) continue; + phonebook.Add(caller); - Caller caller = new Caller(strCallerId, strName, bShow); - phonebook.Add(caller); - - if (_extensiveLogging) - Log.Debug("FRITZ!Box: caller loaded: {0} {1} {2}", caller.callerId, caller.name, caller.show); - } + if (_extensiveLogging) + Log.Debug("FRITZ!Box: caller loaded: {0} {1} {2}", caller.ID, caller.Name, caller.Show); } + } if (_extensiveLogging) Log.Debug("FRITZ!Box: imported {0} callers", phonebook.Count.ToString()); } - private void UpdateTo0220() + public static void SavePhonebook() { + using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) + { + xmlwriter.SetValue("phonebook", "count", phonebook.Count); + + for (int i = 0; i < phonebook.Count; i++) + { + Caller caller = phonebook[i]; + + xmlwriter.SetValue("phonebook", string.Format("callerID{0}", i.ToString()), caller.ID); + xmlwriter.SetValue("phonebook", string.Format("name{0}", i.ToString()), caller.Name); + xmlwriter.SetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), caller.Show); + } + } + } + + public static void UpdateTo0220() + { char[] charSeparators = new char[] { ';' }; using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) @@ -194,46 +230,62 @@ string[] strLCallerId = xmlreader.GetValueAsString("fritzbox", "phonebookCallerId", "").Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); string[] strLName = xmlreader.GetValueAsString("fritzbox", "phonebookName", "").Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); string[] strLShow = xmlreader.GetValueAsString("fritzbox", "phonebookShow", "").Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); - + for (int i = 0; i <= strLCallerId.GetUpperBound(0); i++) { Caller caller = new Caller(strLCallerId[i], strLName[i], bool.Parse(strLShow[i])); phonebook.Add(caller); if (_extensiveLogging) - Log.Debug("FRITZ!Box: caller loaded: {0} {1} {2}", caller.callerId, caller.name, caller.show); + Log.Debug("FRITZ!Box: caller loaded: {0} {1} {2}", caller.ID, caller.Name, caller.Show); } } } - private void SaveSettings() + public static void ImportFritzBoxMonitor(string filepath) { - if (_extensiveLogging) - Log.Info("FRITZ!Box: SaveSettings"); - - using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + try { - xmlwriter.SetValue("fritzbox", "lastVersion", _version.Replace(".", string.Empty)); - } + // Create an instance of StreamReader to read from a file. + // The using statement also closes the StreamReader. + using (StreamReader sr = new StreamReader(filepath)) + { + string line; + // Read and display lines from the file until the end of + // the file is reached. + while ((line = sr.ReadLine()) != null) + { + string[] ar = line.Split(char.Parse(";")); - using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) - { - xmlwriter.SetValue("phonebook", "count", phonebook.Count); + Caller caller = new Caller(); - for (int i = 0; i < phonebook.Count; i++) - { - Caller caller = phonebook[i]; + caller.ID = ar[2]; + caller.Name = String.Format("{0} {1}", ar[0], ar[1]); + caller.Show = true; - xmlwriter.SetValue("phonebook", string.Format("callerID{0}", i.ToString()), caller.callerId); - xmlwriter.SetValue("phonebook", string.Format("name{0}", i.ToString()), caller.name); - xmlwriter.SetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), caller.show); + if (!CallerExists(caller)) + phonebook.Add(caller); + } } } + catch (Exception e) + { + // Let the user know what went wrong. + Log.Error("The file could not be read: {0}", e.Message); + } } + + public static bool CallerExists(Caller caller) + { + for (int i = 0; i < phonebook.Count; i++) + { + if (phonebook[i].ID == caller.ID) + return true; + } + return false; + } #endregion - - public bool IsFritzBoxConnected(string fritzBoxAddress, string fritzBoxPort) { TcpClient TcpClient; @@ -334,16 +386,16 @@ { Caller caller = phonebook[i]; - if (caller.callerId.Equals(callerId)) + if (caller.ID.Equals(callerId)) { - Log.Info("Caller is identified by phonebook as {0}.", caller.name); + Log.Info("Caller is identified by phonebook as {0}.", caller.Name); foundCaller = true; - if (caller.show) + if (caller.Show) { Log.Info("Caller is accepted by phonebook and dialog will be shown."); - DialogOnIncomingCall(caller.name, msn); + DialogOnIncomingCall(caller.Name, msn); } else { Modified: trunk/plugins/FritzBox/FritzBoxSetupFrom.cs =================================================================== --- trunk/plugins/FritzBox/FritzBoxSetupFrom.cs 2007-04-08 11:07:48 UTC (rev 296) +++ trunk/plugins/FritzBox/FritzBoxSetupFrom.cs 2007-04-08 17:34:44 UTC (rev 297) @@ -86,6 +86,8 @@ private MediaPortal.UserInterface.Controls.MPComboBox comboBoxMSNs; private MediaPortal.UserInterface.Controls.MPCheckBox checkBoxShowMsnOnHeading; private PictureBox pictureBox1; + private MediaPortal.UserInterface.Controls.MPButton mpImportFBMonitor; + private OpenFileDialog openFileDialog; /// <summary> /// Erforderliche Designervariable. @@ -133,6 +135,7 @@ this.tabGeneral = new System.Windows.Forms.TabPage(); this.checkBoxExtensiveLogging = new MediaPortal.UserInterface.Controls.MPCheckBox(); this.mpGroupBox1 = new MediaPortal.UserInterface.Controls.MPGroupBox(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.buttonTest = new MediaPortal.UserInterface.Controls.MPButton(); this.textBoxPort = new MediaPortal.UserInterface.Controls.MPTextBox(); this.textBoxAddress = new MediaPortal.UserInterface.Controls.MPTextBox(); @@ -171,10 +174,12 @@ this.buttonCancel = new MediaPortal.UserInterface.Controls.MPButton(); this.buttonSave = new MediaPortal.UserInterface.Controls.MPButton(); this.labelVersion = new MediaPortal.UserInterface.Controls.MPLabel(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.mpImportFBMonitor = new MediaPortal.UserInterface.Controls.MPButton(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.tabControlFritzBoxSettings.SuspendLayout(); this.tabGeneral.SuspendLayout(); this.mpGroupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.tabIncoming.SuspendLayout(); this.groupBoxPhonebook.SuspendLayout(); this.groupBoxNotify.SuspendLayout(); @@ -183,7 +188,6 @@ this.tabPhonebook.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCaller)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // tabControlFritzBoxSettings @@ -242,6 +246,16 @@ this.mpGroupBox1.TabStop = false; this.mpGroupBox1.Text = "connection"; // + // pictureBox1 + // + this.pictureBox1.Image = global::FritzBox.Properties.Resources.FritzBoxIconTransparent; + this.pictureBox1.Location = new System.Drawing.Point(6, 20); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(97, 99); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 2; + this.pictureBox1.TabStop = false; + // // buttonTest // this.buttonTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -318,6 +332,7 @@ // this.groupBoxPhonebook.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxPhonebook.Controls.Add(this.mpImportFBMonitor); this.groupBoxPhonebook.Controls.Add(this.checkBoxSaveUnknownCaller); this.groupBoxPhonebook.Controls.Add(this.checkBoxShowUnknownCaller); this.groupBoxPhonebook.Controls.Add(this.checkBoxUsePhonebook); @@ -685,15 +700,16 @@ this.labelVersion.TabIndex = 13; this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // pictureBox1 + // mpImportFBMonitor // - this.pictureBox1.Image = global::FritzBox.Properties.Resources.FritzBoxIconTransparent; - this.pictureBox1.Location = new System.Drawing.Point(6, 20); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(97, 99); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox1.TabIndex = 2; - this.pictureBox1.TabStop = false; + this.mpImportFBMonitor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.mpImportFBMonitor.Location = new System.Drawing.Point(355, 20); + this.mpImportFBMonitor.Name = "mpImportFBMonitor"; + this.mpImportFBMonitor.Size = new System.Drawing.Size(150, 23); + this.mpImportFBMonitor.TabIndex = 3; + this.mpImportFBMonitor.Text = "Import FRITZ!Box Monitor"; + this.mpImportFBMonitor.UseVisualStyleBackColor = true; + this.mpImportFBMonitor.Click += new System.EventHandler(this.mpImportFBMonitor_Click); // // FritzBoxSetupForm // @@ -715,6 +731,7 @@ this.tabGeneral.PerformLayout(); this.mpGroupBox1.ResumeLayout(false); this.mpGroupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.tabIncoming.ResumeLayout(false); this.groupBoxPhonebook.ResumeLayout(false); this.groupBoxPhonebook.PerformLayout(); @@ -727,7 +744,6 @@ this.tabPhonebook.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCaller)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } @@ -778,50 +794,11 @@ checkBoxShowUnknownCaller.Enabled = checkBoxUsePhonebook.Checked; checkBoxSaveUnknownCaller.Enabled = checkBoxUsePhonebook.Checked; } - - if ((FritzBox._lastVersion < 0220) && (!File.Exists(Config.GetFile(Config.Dir.Config, "fritzbox.xml")))) - UpdateTo0220(); - else - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) - { - int countCaller = xmlreader.GetValueAsInt("phonebook", "count", 0); - - for (int i = 0; i < countCaller; i++) - { - string strCallerId = xmlreader.GetValueAsString("phonebook", string.Format("callerID{0}", i.ToString()), ""); - string strName = xmlreader.GetValueAsString("phonebook", string.Format("name{0}", i.ToString()), ""); - bool bShow = xmlreader.GetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), false); - - if (strCallerId == "") continue; - if (strCallerId == null) continue; - if (strName == "") continue; - if (strName == null) continue; - - dataGridView.Rows.Add(strCallerId, strName, bShow); - } - } + + FritzBox.LoadPhonebook(); + RefreshDataGridView(); } - private void UpdateTo0220() - { - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - string strCallerId = xmlreader.GetValueAsString("fritzbox", "phonebookCallerId", ""); - string strName = xmlreader.GetValueAsString("fritzbox", "phonebookName", ""); - string strShow = xmlreader.GetValueAsString("fritzbox", "phonebookShow", ""); - - if (strCallerId != "") - { - string[] strListCallerId = strCallerId.Split(';'); - string[] strListName = strName.Split(';'); - string[] strListShow = strShow.Split(';'); - - for (int i = 0; i < strListCallerId.GetUpperBound(0); i++) - dataGridView.Rows.Add(strListCallerId[i], strListName[i], bool.Parse(strListShow[i])); - } - } - } - private void SaveSettings() { Log.Info("FRITZ!Box: SaveSettings"); @@ -858,21 +835,8 @@ xmlwriter.SetValueAsBool("fritzbox", "saveUnknownCaller", checkBoxSaveUnknownCaller.Checked); } - using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "fritzbox.xml"))) - { - xmlwriter.SetValue("phonebook", "count", dataGridView.RowCount - 1); - - for (int i = 0; i < dataGridView.RowCount - 1; i++) - { - string strCallerId = dataGridView.Rows[i].Cells[0].Value.ToString(); - string strName = dataGridView.Rows[i].Cells[1].Value.ToString(); - bool strShow = bool.Parse(dataGridView.Rows[i].Cells[2].Value.ToString()); - - xmlwriter.SetValue("phonebook", string.Format("callerID{0}", i.ToString()), strCallerId); - xmlwriter.SetValue("phonebook", string.Format("name{0}", i.ToString()), strName); - xmlwriter.SetValueAsBool("phonebook", string.Format("show{0}", i.ToString()), strShow); - } - } + SaveDataGridView(); + FritzBox.SavePhonebook(); } private void buttonSave_Click(object sender, EventArgs e) @@ -1020,13 +984,6 @@ MessageBox.Show("CallerID is empty. Please type in the correct CallerID."); return false; } - - if (textBoxCallerId.Text.Contains(";")) - { - textBoxCallerId.Focus(); - MessageBox.Show("CallerID: A ';' ist not allowed."); - return false; - } if (dataGridView.Rows[dataGridView.NewRowIndex].Selected) for (int i = 0; i < dataGridView.Rows.Count - 1; i++) @@ -1049,13 +1006,6 @@ return false; } - if (textBoxCallerName.Text.Contains(";")) - { - textBoxCallerName.Focus(); - MessageBox.Show("Name: A ';' ist not allowed."); - return false; - } - return true; } @@ -1086,5 +1036,40 @@ pictureBoxCaller.ImageLocation = MediaPortal.Util.Utils.GetCoverArt(Thumbs.Yac, textBoxCallerName.Text); } } + + private void mpImportFBMonitor_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + FritzBox.ImportFritzBoxMonitor(openFileDialog.FileName); + RefreshDataGridView(); + } + } + + private void RefreshDataGridView() + { + dataGridView.Rows.Clear(); + + for (int i = 0; i < FritzBox.phonebook.Count; i++) + { + dataGridView.Rows.Add(FritzBox.phonebook[i].ID, FritzBox.phonebook[i].Name, FritzBox.phonebook[i].Show); + } + } + + private void SaveDataGridView() + { + FritzBox.phonebook.Clear(); + + for (int i = 0; i < dataGridView.RowCount - 1; i++) + { + Caller caller = new Caller(); + + caller.ID = dataGridView.Rows[i].Cells[0].Value.ToString(); + caller.Name = dataGridView.Rows[i].Cells[1].Value.ToString(); + caller.Show = bool.Parse(dataGridView.Rows[i].Cells[2].Value.ToString()); + + FritzBox.phonebook.Add(caller); + } + } } } \ No newline at end of file Modified: trunk/plugins/FritzBox/FritzBoxSetupFrom.resx =================================================================== --- trunk/plugins/FritzBox/FritzBoxSetupFrom.resx 2007-04-08 11:07:48 UTC (rev 296) +++ trunk/plugins/FritzBox/FritzBoxSetupFrom.resx 2007-04-08 17:34:44 UTC (rev 297) @@ -126,6 +126,9 @@ <metadata name="colShow.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>True</value> </metadata> + <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>17, 17</value> + </metadata> <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <value> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |