From: <kro...@us...> - 2010-12-05 19:32:47
|
Revision: 4007 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4007&view=rev Author: kroko_koenig Date: 2010-12-05 19:32:41 +0000 (Sun, 05 Dec 2010) Log Message: ----------- add ids for pictures Modified Paths: -------------- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-04 18:31:25 UTC (rev 4006) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-05 19:32:41 UTC (rev 4007) @@ -38,10 +38,13 @@ using MediaPortal.GUI.Library; using MediaPortal.Utils; using MediaPortal.Database; +using MediaPortal.Configuration; using MediaPortal.Player; using MediaPortal.Playlists; +using SQLite.NET; + namespace AndroidRemote { public class Request @@ -53,6 +56,8 @@ private static Bitmap actualCover = null; private static string[] listAllPictures = null; + private SQLiteClient sqlClient; + public Request(Socket Socket) { socket = Socket; @@ -193,6 +198,26 @@ ReplyPicturesDbByDate(date); } } + if (req.StartsWith("getpicture")) + { + int pos = req.IndexOf("?"); + if (pos > 0) + { + string id = req.Substring(pos + 1); + id = id.Replace("id=", ""); + ReplyPicturesDbFile(id); + } + } + if (req.StartsWith("getthumb")) + { + int pos = req.IndexOf("?"); + if (pos > 0) + { + string id = req.Substring(pos + 1); + id = id.Replace("id=", ""); + ReplyPicturesDbThumbFile(id); + } + } } #endregion @@ -732,6 +757,11 @@ } private void ReplyPicturesDbByDate(string Date) { + sqlClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "PictureDatabase.db3")); + sqlClient.BusyRetries = 10; + sqlClient.BusyRetryDelay = 100; + DatabaseUtility.SetPragmas(sqlClient); + string msg = string.Empty; // header msg += "HTTP/1.0 200 Ok\r\n"; @@ -743,17 +773,16 @@ msg += "<Database>\r\n"; msg += "<Date>" + Date + "</Date>\r\n"; - List<string> aList = new List<string>(); - MediaPortal.Picture.Database.PictureDatabase.ListPicsByDate(Date, ref aList); + List<string[]> aList = new List<string[]>(); + //MediaPortal.Picture.Database.PictureDatabase.ListPicsByDate(Date, ref aList); // we dont get the ids... pff + ListPicsByDate(Date, ref aList); - foreach (string year in aList) + foreach (string[] item in aList) { - if (year != string.Empty) - { - msg += "<Item>\r\n"; - msg += "<Picture>" + HttpUtility.HtmlEncode(year) + "</Picture>\r\n"; - msg += "</Item>\r\n"; - } + msg += "<Item>\r\n"; + msg += "<ID>" + HttpUtility.HtmlEncode(item[0]) + "</ID>\r\n"; + msg += "<Name>" + HttpUtility.HtmlEncode(item[1]) + "</Name>\r\n"; + msg += "</Item>\r\n"; } msg += "</Database>\r\n\r\n"; @@ -761,7 +790,100 @@ sendMessage(socket, msg); AndroidServer.logDebug("Reply db pictures date"); } + private void ReplyPicturesDbFile(string ID) + { + sqlClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "PictureDatabase.db3")); + sqlClient.BusyRetries = 10; + sqlClient.BusyRetryDelay = 100; + DatabaseUtility.SetPragmas(sqlClient); + string filePath = GetPathById(ID); + + if (File.Exists(filePath)) + { + Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); + byte[] b; + + if ((bit.Width > 600) || (bit.Height > 600)) + { + Bitmap thumb = (Bitmap)bit.Clone(); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 600, 600, false, true); + + b = BildToByteArray((Image)thumb); + } + else + { + b = BildToByteArray((Image)bit); + } + + if (b != null) + { + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: image/jpeg" + "\r\n"; + msg += "Content-Length: " + b.Length + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + sendMessage(socket, msg); + // content + sendBytes(socket, b); + AndroidServer.logDebug("Reply picture file"); + } + else + { + SendServerError(filePath, "ReplyPictureFile"); + } + } + else + { + SendErrorFile(filePath); + } + } + private void ReplyPicturesDbThumbFile(string ID) + { + sqlClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "PictureDatabase.db3")); + sqlClient.BusyRetries = 10; + sqlClient.BusyRetryDelay = 100; + DatabaseUtility.SetPragmas(sqlClient); + + string filePath = GetPathById(ID); + + if (File.Exists(filePath)) + { + Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); + byte[] b; + + Bitmap thumb = (Bitmap)bit.Clone(); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 85, 85, false, true); + + b = BildToByteArray((Image)thumb); + + if (b != null) + { + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: image/jpeg" + "\r\n"; + msg += "Content-Length: " + b.Length + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + sendMessage(socket, msg); + // content + sendBytes(socket, b); + AndroidServer.logDebug("Reply picture file"); + } + else + { + SendServerError(filePath, "ReplyPictureFile"); + } + } + else + { + SendErrorFile(filePath); + } + } + private void ReplyMusicDir(string dir, string request) { if (Directory.Exists(dir)) @@ -1376,5 +1498,69 @@ { return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName); } + + public int ListPicsByDate(string Date, ref List<string[]> Pics) + { + int Count = 0; + { + if (sqlClient == null) + { + return 0; + } + string strSQL = "select idPicture,strFile from picture where strDateTaken like '" + Date + "%' order by 1"; + SQLiteResultSet result; + try + { + result = sqlClient.Execute(strSQL); + if (result != null) + { + for (Count = 0; Count < result.Rows.Count; Count++) + { + string[] vals = new string[2]; + vals[0] = DatabaseUtility.Get(result, Count, 0); + vals[1] = Path.GetFileName(DatabaseUtility.Get(result, Count, 1)); + Pics.Add(vals); + } + } + } + catch (Exception ex) + { + Log.Error("MediaPortal.Picture.Database exception getting Picture by Date err:{0} stack:{1}", ex.Message, + ex.StackTrace); + //Open(); + } + return Count; + } + } + public string GetPathById(string ID) + { + { + if (sqlClient == null) + { + return string.Empty; + } + string strSQL = "select strFile from picture where idPicture='" + ID + "'"; + SQLiteResultSet result; + try + { + result = sqlClient.Execute(strSQL); + if (result != null) + { + + if (result.Rows.Count == 1) + { + return DatabaseUtility.Get(result, 0, 0); + } + } + } + catch (Exception ex) + { + Log.Error("MediaPortal.Picture.Database exception getting Picture by Date err:{0} stack:{1}", ex.Message, + ex.StackTrace); + //Open(); + } + return string.Empty; + } + } } } Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |