Ticket #4400: phpgallery2.patch
File phpgallery2.patch, 22.7 KB (added by , 18 years ago) |
---|
-
mythgallery/glsingleview.cpp
37 37 // MythTV plugin headers 38 38 #include <mythtv/mythcontext.h> 39 39 #include <mythtv/util.h> 40 #include <mythtv/httpcomms.h> 40 41 41 42 // MythGallery headers 42 43 #include "glsingleview.h" … … 94 95 m_effect_cube_yrot(0.0f), 95 96 m_effect_cube_zrot(0.0f) 96 97 { 98 m_phpGalleryURL = gContext->GetSetting("PHPGalleryURL", NULL); 97 99 m_slideshow_timer = new QTimer(this); 98 100 RegisterEffects(); 99 101 … … 506 508 if (QFile::exists(item->GetPath())) 507 509 { 508 510 break; 509 } 511 } 512 else if (m_phpGalleryURL.startsWith("http://",false)) 513 { 514 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 515 HttpComms::getHttpFile(item->GetPath(), url, 20000); 516 break; 517 } 510 518 } 511 519 if (m_pos == oldpos) 512 520 { … … 539 547 m_pos = m_slideshow_sequence->prev(); 540 548 541 549 ThumbItem *item = m_itemList.at(m_pos); 542 if (item && QFile::exists(item->GetPath())) 543 break; 550 if (item) 551 { 552 if (QFile::exists(item->GetPath())) 553 { 554 break; 555 } 556 else if (m_phpGalleryURL.startsWith("http://",false)) 557 { 558 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 559 HttpComms::getHttpFile(item->GetPath(), url, 20000); 560 break; 561 } 562 } 544 563 545 564 if (m_pos == oldpos) 546 565 { … … 572 591 return; 573 592 } 574 593 594 if (!QFile::exists(item->GetPath()) && m_phpGalleryURL.startsWith("http://",false)){ 595 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 596 HttpComms::getHttpFile(item->GetPath(), url, 20000); 597 } 575 598 QImage image(item->GetPath()); 576 599 if (image.isNull()) 577 600 return; -
mythgallery/glsingleview.h
133 133 float m_effect_cube_xrot; 134 134 float m_effect_cube_yrot; 135 135 float m_effect_cube_zrot; 136 QString m_phpGalleryURL; 136 137 }; 137 138 138 139 #endif // USING_OPENGL -
mythgallery/phpgalleryutil.cpp
1 // 2 // C++ Implementation: PhpGalleryUtil 3 // 4 // Description: 5 // 6 // 7 // Author: mythtv <mythtv@jshoor-media>, (C) 2007 8 // 9 // Copyright: See COPYING file that comes with this distribution 10 // 11 // 12 13 #include <qdir.h> 14 15 #include <mythtv/httpcomms.h> 16 #include <mythtv/mythcontext.h> 17 18 19 #include "phpgalleryutil.h" 20 21 PhpGalleryUtil::PhpGalleryUtil() 22 { 23 m_startURL = gContext->GetSetting("PHPGalleryURL"); 24 m_startDir = gContext->GetSetting("GalleryDir"); 25 m_refreshCache = gContext->GetNumSetting("PHPGalleryRefreshCache"); 26 QString response = MakeRequest("fetch-albums&g2_form%5Bno_perms%5D=yes"); 27 QStringList responseLines = QStringList::split("\n",response); 28 QString albumNumber = NULL; 29 for ( QStringList::Iterator it = responseLines.begin(); it != responseLines.end(); ++it ) { 30 QStringList nameList; 31 QString propValue; 32 ReadResponseLine(*it, nameList, propValue); 33 if ((nameList[0].compare("album")==0)&&((nameList.last()).compare(albumNumber)!=0)) { 34 QString albumName=NULL; 35 QString albumTitle=NULL; 36 QString albumParent=NULL; 37 albumNumber = nameList.last(); 38 if (nameList[1].compare("name")==0){ 39 albumName = propValue; 40 } 41 ReadResponseLine(*++it, nameList, propValue); 42 if ((nameList[1].compare("title")==0)&&((nameList.last()).compare(albumNumber)==0)) { 43 albumTitle = propValue; 44 } 45 it++; 46 ReadResponseLine(*++it, nameList, propValue); 47 if ((nameList[1].compare("parent")==0)&&((nameList.last()).compare(albumNumber)==0)) { 48 albumParent = propValue; 49 } 50 if (albumParent.compare("0")==0){ 51 m_rootAlbum = new Album(albumName, albumTitle, albumParent);; 52 } 53 else 54 { 55 Album *album = new Album(albumName, albumTitle, albumParent); 56 m_all_albums.append(album); 57 m_temp_album_dict.insert(album->GetName(),album); 58 } 59 60 } 61 62 } 63 QPtrListIterator<Album> it( m_all_albums ); 64 Album *thisalbum; 65 66 while ((thisalbum = it.current()) != 0){ 67 thisalbum->SetPath(BuildPath(thisalbum,thisalbum->GetName())); 68 m_album_dict.insert(thisalbum->GetName(),thisalbum); 69 ++it; 70 } 71 72 } 73 74 QString PhpGalleryUtil::BuildPath(Album *album, QString path){ 75 if (album->GetParent().compare(m_rootAlbum->GetName())==0){ 76 path.prepend(m_startDir + "/"); 77 QDir dir(path); 78 if (!dir.exists()){ 79 dir.mkdir(path,true); 80 } 81 return path; 82 } else { 83 path.prepend(album->GetParent()+"/"); 84 return BuildPath(m_temp_album_dict.find(album->GetParent()),path); 85 } 86 } 87 88 89 void PhpGalleryUtil::ReadResponseLine(QString responseLine, QStringList &nameList, QString &propValue){ 90 QStringList propertyMap = QStringList::split("=", responseLine); 91 QString propName = propertyMap[0]; 92 propValue = propertyMap[1]; 93 nameList = QStringList::split(".", propName); 94 } 95 96 97 bool PhpGalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir, 98 ThumbDict *itemDict, ThumbGenerator* thumbGen) 99 { 100 101 Album *album; 102 QString album_name; 103 if (dir.compare(m_startDir)==0){ 104 album = m_rootAlbum; 105 album_name = m_rootAlbum->GetName(); 106 } else { 107 album_name = dir.section("/",-1); 108 album = m_album_dict.find(album_name); 109 } 110 111 //go through m_all_albums and find any albums that have this album as a parent 112 QPtrListIterator<Album> it( m_all_albums ); 113 Album *thisalbum; 114 115 while ((thisalbum = it.current()) != 0){ 116 if (thisalbum->GetParent().compare(album_name) == 0){ 117 GetItems(thisalbum, itemList, itemDict, thumbGen, true, thisalbum->GetTitle(), thisalbum->GetPath()); 118 } 119 ++it; 120 } 121 122 //get Items for this album 123 GetItems(album, itemList, itemDict, thumbGen, false); 124 125 return true; 126 } 127 128 129 bool PhpGalleryUtil::GetItems(Album *album, ThumbList& thumbList, ThumbDict *itemDict, ThumbGenerator* thumbGen, bool highlight, QString caption, QString path){ 130 131 if (highlight){ 132 QDir dir(album->GetPath()); 133 QStringList files = dir.entryList("*-highlight.jpg"); 134 if (files[0] != NULL && !m_refreshCache ){ 135 QString itemName = files[0].section("-",0,0); 136 ThumbItem *thumbItem = new ThumbItem(itemName, path, true); 137 thumbItem->SetCaption(caption); 138 QImage *image = new QImage(album->GetPath()+ "/" + files[0]); 139 QPixmap *pixmap = new QPixmap(*image); 140 thumbItem->SetPixmap(pixmap); 141 thumbList.append(thumbItem); 142 if (itemDict) 143 itemDict->insert(thumbItem->GetName(), thumbItem); 144 if (thumbGen) 145 thumbGen->addFile(thumbItem->GetName()); 146 return true; 147 } 148 } 149 QString response = MakeRequest("fetch-album-images&g2_form%5Bset_albumName%5D=" + album->GetName()); 150 QStringList responseLines = QStringList::split("\n",response); 151 QString itemNumber = NULL; 152 for ( QStringList::Iterator it = responseLines.begin(); it != responseLines.end(); ++it ) { 153 QStringList nameList; 154 QString propValue; 155 ReadResponseLine(*it, nameList, propValue); 156 if ((nameList[0].compare("image")==0)&&(nameList.last().compare(itemNumber)!=0)) { 157 158 // image.name.1=12227 159 // image.raw_width.1=3008 160 // image.raw_height.1=2000 161 // image.raw_filesize.1=1196696 162 // image.resizedName.1=12228 if exists 163 // image.resized_width.1=640 if exists 164 // image.resized_height.1=426 if exists 165 // image.thumbName.1=12229 166 // image.thumb_width.1=150 167 // image.thumb_height.1=100 168 // image.forceExtension.1=jpg 169 // image.caption.1=DSC_0005.JPG 170 // image.title.1=DSC_0005.JPG 171 // image.hidden.1=no 172 173 QString itemName=NULL; 174 QString thumbName=NULL; 175 QString itemTitle=NULL; 176 QString itemParent=NULL; 177 QString itemExtension=NULL; 178 179 itemNumber = nameList.last(); 180 if (nameList[1].compare("name")==0){ 181 itemName = propValue; 182 } 183 it+=4; 184 ReadResponseLine(*it, nameList, propValue); 185 if (nameList[1].compare("resizedName")==0){ 186 itemName = propValue; 187 it+=3; 188 } 189 190 ReadResponseLine(*it, nameList, propValue); 191 if (nameList[1].compare("thumbName")==0){ 192 thumbName = propValue; 193 } 194 it+=2; 195 ReadResponseLine(*++it, nameList, propValue); 196 if ((nameList[1].compare("forceExtension")==0)&&(nameList.last().compare(itemNumber)==0)) { 197 itemExtension = propValue; 198 } 199 ++it; 200 ReadResponseLine(*++it, nameList, propValue); 201 if ((nameList[1].compare("title")==0)&&(nameList.last().compare(itemNumber)==0)) { 202 itemTitle = propValue; 203 } 204 //make and set QPixmap 205 QDir dir(album->GetPath()); 206 if (!dir.exists()) 207 dir.mkdir(album->GetPath()); 208 209 QString tempFile; 210 if (highlight){ 211 tempFile = album->GetPath() + "/" + itemName + "-highlight.jpg"; 212 } else { 213 tempFile = album->GetPath() + "/" + thumbName + "." + itemExtension; 214 } 215 QString url = m_startURL+"?g2_view=core.DownloadItem&g2_itemId="+thumbName; 216 217 if (!QFile::exists(tempFile)|| m_refreshCache ){ 218 HttpComms::getHttpFile(tempFile, url, 20000, 3); 219 } 220 QImage *image = new QImage(tempFile); 221 QPixmap *pixmap = new QPixmap(*image); 222 223 ThumbItem *thumbItem; 224 if (highlight){ //if album 225 thumbItem = new ThumbItem(itemName, path, true); 226 thumbItem->SetCaption(caption); 227 } else{ 228 thumbItem = new ThumbItem(itemName, album->GetPath()+"/"+itemName+"."+itemExtension, false); 229 thumbItem->SetCaption(itemTitle); 230 } 231 thumbItem->SetPixmap(pixmap); 232 thumbList.append(thumbItem); 233 if (itemDict) 234 itemDict->insert(thumbItem->GetName(), thumbItem); 235 236 if (thumbGen) 237 thumbGen->addFile(thumbItem->GetName()); 238 if (highlight){ 239 return true; 240 } 241 } 242 } 243 if (highlight) //If we have gotten this far it means the album does not have any items of its own, lets check for a highlight from a subalbum recursively 244 { 245 //go through m_all_albums and find any albums that have this album as a parent 246 QPtrListIterator<Album> it( m_all_albums ); 247 Album *thisalbum; 248 while ((thisalbum = it.current()) != 0){ 249 if (thisalbum->GetParent().compare(album->GetName()) == 0){ 250 if (GetItems(thisalbum, thumbList, itemDict, thumbGen, true, album->GetTitle(),album->GetPath())){ 251 return true; 252 } 253 } 254 ++it; 255 } 256 return false; 257 } 258 return true; 259 } 260 261 QString PhpGalleryUtil::MakeRequest(QString cmd){ 262 QUrl url = m_startURL; 263 264 // Make Request to server 265 QByteArray aBuffer; 266 QTextStream os( aBuffer, IO_WriteOnly ); 267 os << "g2_controller=remote%3AGalleryRemote&protocol_version=2.11&g2_form%5Bcmd%5D="; 268 os << cmd; 269 QBuffer buff( aBuffer ); 270 QHttpRequestHeader header; 271 272 header.setValue("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint,application/msword, application/x-shockwave-flash, */*" ); 273 header.setValue("Accept-Language", "en-us"); 274 header.setValue("Content-Type", "application/x-www-form-urlencoded"); 275 header.setValue("Connection", "Keep-Alive"); 276 header.setValue("Cache-Control", "no-cache"); 277 278 QString response = HttpComms::postHttp( url, 279 &header, 280 &buff, 281 20000, // ms 282 3, // retries 283 0, // redirects 284 false, // allow gzip 285 NULL, // login 286 true ); 287 return response; 288 289 } 290 291 Album::Album(QString albumName, QString albumTitle, QString albumParent, QString albumPath){ 292 m_name = albumName; 293 m_title = albumTitle; 294 m_parent = albumParent; 295 m_path = albumPath; 296 } 297 298 Album::Album(QString albumName, QString albumTitle, QString albumParent){ 299 m_name = albumName; 300 m_title = albumTitle; 301 m_parent = albumParent; 302 } -
mythgallery/phpgalleryutil.h
1 // 2 // C++ Interface: PhpGalleryUtil 3 // 4 // Description: 5 // 6 // 7 // Author: mythtv <mythtv@jshoor-media>, (C) 2007 8 // 9 // Copyright: See COPYING file that comes with this distribution 10 // 11 // 12 13 #include <qstringlist.h> 14 #include <qbuffer.h> 15 #include "thumbview.h" 16 #include "thumbgenerator.h" 17 18 class Album 19 { 20 public: 21 Album(QString albumName, QString albumTitle, QString albumParent, QString path); 22 Album(QString albumName, QString albumTitle, QString albumParent); 23 QString GetName(){return m_name;} 24 QString GetTitle(){return m_title;} 25 QString GetParent(){return m_parent;} 26 QString GetPath(){return m_path;} 27 void SetPath(QString path){m_path = path;} 28 void SetItems(ThumbList *itemList){m_items = itemList;} 29 private: 30 QString m_name; 31 QString m_title; 32 QString m_parent; 33 QString m_path; 34 ThumbList *m_items; 35 }; 36 37 class PhpGalleryUtil 38 { 39 public: 40 PhpGalleryUtil(); 41 bool LoadDirectory(ThumbList &itemList, const QString &dir, 42 ThumbDict *itemDict, ThumbGenerator *thumbGen); 43 Album *GetRootAlbum(){return m_rootAlbum;} 44 45 46 47 private: 48 void ReadResponseLine(QString responseLine, QStringList &nameList, QString &propValue); 49 bool GetItems(Album *album, ThumbList& thumblist, ThumbDict *itemDict, ThumbGenerator* thumbGen, bool highlight, QString caption = NULL, QString path = NULL); 50 51 QString MakeRequest(QString cmd); 52 QString BuildPath(Album *album, QString path); 53 QString m_startURL; 54 QString m_startDir; 55 Album *m_rootAlbum; 56 int m_refreshCache; 57 QPtrList<Album> m_all_albums; 58 QDict<Album> m_temp_album_dict; 59 QDict<Album> m_album_dict; 60 61 62 }; 63 -
mythgallery/singleview.cpp
34 34 // MythTV plugin headers 35 35 #include <mythtv/mythcontext.h> 36 36 #include <mythtv/util.h> 37 #include <mythtv/httpcomms.h> 37 38 38 39 // MythGallery headers 39 40 #include "singleview.h" … … 88 89 m_effect_milti_circle_out_points(4), 89 90 m_effect_circle_out_points(4) 90 91 { 92 m_phpGalleryURL = gContext->GetSetting("PHPGalleryURL", NULL); 91 93 m_slideshow_timer = new QTimer(this); 92 94 RegisterEffects(); 93 95 … … 505 507 if (QFile::exists(item->GetPath())) 506 508 { 507 509 break; 508 } 510 } 511 else if (m_phpGalleryURL.startsWith("http://",false)) 512 { 513 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 514 HttpComms::getHttpFile(item->GetPath(), url, 20000); 515 break; 516 } 509 517 } 510 518 if (m_pos == oldpos) 511 519 { … … 535 543 m_pos = m_slideshow_sequence->prev(); 536 544 537 545 ThumbItem *item = m_itemList.at(m_pos); 538 if (item && QFile::exists(item->GetPath())) 539 break; 546 if (item) 547 { 548 if (QFile::exists(item->GetPath())) 549 { 550 break; 551 } 552 else if (m_phpGalleryURL.startsWith("http://",false)) 553 { 554 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 555 HttpComms::getHttpFile(item->GetPath(), url, 20000); 556 break; 557 } 558 } 540 559 541 560 if (m_pos == oldpos) 542 561 { … … 567 586 m_movieState = 1; 568 587 return; 569 588 } 589 if (!QFile::exists(item->GetPath()) && m_phpGalleryURL.startsWith("http://",false)){ 590 QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+item->GetName(); 591 HttpComms::getHttpFile(item->GetPath(), url, 20000); 592 } 570 593 571 594 m_image.load(item->GetPath()); 572 595 if (m_image.isNull()) -
mythgallery/mythgallery.pro
29 29 HEADERS += qtiffio.h galleryutil.h 30 30 HEADERS += constants.h 31 31 HEADERS += thumbgenerator.h thumbview.h 32 HEADERS += phpgalleryutil.h 32 33 SOURCES += iconview.cpp singleview.cpp 33 34 SOURCES += imageview.cpp 34 35 SOURCES += gallerysettings.cpp dbcheck.cpp 35 36 SOURCES += qtiffio.cpp galleryutil.cpp 36 37 SOURCES += thumbgenerator.cpp thumbview.cpp 37 SOURCES += main.cpp 38 SOURCES += phpgalleryutil.cpp 39 SOURCES += main.cpp 38 40 39 41 opengl { 40 42 SOURCES *= glsingleview.cpp gltexture.cpp -
mythgallery/gallerysettings.cpp
34 34 return gc; 35 35 }; 36 36 37 static HostLineEdit *MythGalleryPHPGalleryURL() 38 { 39 HostLineEdit *gc = new HostLineEdit("PHPGalleryURL"); 40 gc->setLabel(QObject::tr("URL of PHP Gallery")); 41 gc->setHelpText(QObject::tr("For example: http://www.mygallery.com/gallery2/main.php")); 42 return gc; 43 }; 44 45 static HostCheckBox *MythGalleryRefreshPHPGalleryCache() 46 { 47 HostCheckBox *gc = new HostCheckBox("PHPGalleryRefreshCache"); 48 gc->setLabel(QObject::tr("Refresh PHP Gallery Cache")); 49 gc->setValue(false); 50 gc->setHelpText(QObject::tr("Do not use existing cached PHP Gallery data. This will slow load time significantly. Must uncheck when done to start using cached data again.")); 51 return gc; 52 }; 53 37 54 static HostComboBox *MythGallerySortOrder() 38 55 { 39 56 HostComboBox *gc = new HostComboBox("GallerySortOrder"); … … 215 232 general->setLabel(QObject::tr("MythGallery Settings (General)")); 216 233 general->addChild(MythGalleryDir()); 217 234 general->addChild(MythGalleryThumbnailLocation()); 235 general->addChild(MythGalleryPHPGalleryURL()); 236 general->addChild(MythGalleryRefreshPHPGalleryCache()); 218 237 general->addChild(MythGallerySortOrder()); 219 238 general->addChild(MythGalleryImportDirs()); 220 239 general->addChild(MythGalleryMoviePlayerCmd()); -
mythgallery/singleview.h
131 131 float m_effect_multi_circle_out_delta_alpha; 132 132 QPointArray m_effect_milti_circle_out_points; 133 133 QPointArray m_effect_circle_out_points; 134 QString m_phpGalleryURL; 134 135 }; 135 136 136 137 #endif /* SINGLEVIEW_H */ -
mythgallery/iconview.cpp
87 87 ":", gContext->GetSetting("GalleryImportDirs"))), 88 88 m_errorStr(QString::null) 89 89 { 90 m_phpGalleryURL = gContext->GetSetting("PHPGalleryURL", NULL); 91 if (m_phpGalleryURL!= NULL){ 92 m_phpGalleryUtil = new PhpGalleryUtil(); 93 if (m_phpGalleryUtil->GetRootAlbum() == NULL){ 94 m_errorStr = tr("MythGallery failed any PHP Gallery items. Probably a bad URL: %1").arg(m_phpGalleryURL); 95 return; 96 } 97 } 90 98 m_itemList.setAutoDelete(true); 91 99 m_itemDict.setAutoDelete(false); 92 100 … … 892 900 item->setData(new MenuAction(&IconView::HandleSubMenuMetadata)); 893 901 item = new UIListBtnTypeItem(m_menuType, tr("Marking...")); 894 902 item->setData(new MenuAction(&IconView::HandleSubMenuMark)); 895 item = new UIListBtnTypeItem(m_menuType, tr("File...")); 896 item->setData(new MenuAction(&IconView::HandleSubMenuFile)); 903 if(!m_phpGalleryURL.startsWith("http://",false)){ 904 item = new UIListBtnTypeItem(m_menuType, tr("File...")); 905 item->setData(new MenuAction(&IconView::HandleSubMenuFile)); 906 } 897 907 item = new UIListBtnTypeItem(m_menuType, tr("Settings")); 898 908 item->setData(new MenuAction(&IconView::HandleSettings)); 899 909 … … 980 990 m_itemList.clear(); 981 991 m_itemDict.clear(); 982 992 983 m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, m_sortorder, 993 if (m_phpGalleryURL.startsWith("http://",false)) 994 { 995 //PHP Gallery installation 996 997 m_isGallery = m_phpGalleryUtil->LoadDirectory(m_itemList, dir, &m_itemDict, m_thumbGen); 998 } 999 else 1000 { 1001 m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, m_sortorder, 984 1002 false, &m_itemDict, m_thumbGen); 1003 } 985 1004 986 1005 m_lastRow = max((int)ceilf((float)m_itemList.count() / 987 1006 (float)m_nCols) - 1, 0); -
mythgallery/iconview.h
28 28 29 29 // MythGallery headers 30 30 #include "thumbview.h" 31 #include "phpgalleryutil.h" 31 32 32 33 class XMLParse; 33 34 class UIListBtnType; … … 114 115 QDict<ThumbItem> m_itemDict; 115 116 QStringList m_itemMarked; 116 117 QString m_galleryDir; 117 118 QString m_phpGalleryURL; 119 118 120 XMLParse *m_theme; 119 121 QRect m_menuRect; 120 122 QRect m_textRect; … … 160 162 QStringList m_paths; 161 163 162 164 QString m_errorStr; 165 PhpGalleryUtil *m_phpGalleryUtil; 163 166 164 167 typedef void (IconView::*MenuAction)(void); 165 168 -
mythgallery/thumbgenerator.h
26 26 #include <qstring.h> 27 27 #include <qstringlist.h> 28 28 #include <qimage.h> 29 #include <qfileinfo.h> 29 30 30 31 class QObject; 31 32 class QImage;