Index: mythgallery/mythgallery/phpgalleryutil.cpp
===================================================================
--- mythgallery/mythgallery/phpgalleryutil.cpp	(revision 0)
+++ mythgallery/mythgallery/phpgalleryutil.cpp	(revision 0)
@@ -0,0 +1,505 @@
+//
+// C++ Implementation: PhpGalleryUtil
+//
+// Description: 
+//
+//
+// Author: mythtv <mythtv@jshoor-media>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <qdir.h>
+#include <qhbox.h>
+#include <qvbox.h>
+#include <qapplication.h>
+#include <mythtv/mythcontext.h>
+#include <mythtv/mythwidgets.h>
+#include <mythtv/lcddevice.h>
+
+#include "phpgalleryutil.h"
+
+QString PhpGalleryUtil::m_startURL;
+QString PhpGalleryUtil::m_startDir;
+Album *PhpGalleryUtil::m_rootAlbum;
+int PhpGalleryUtil::m_refreshCache;
+QPtrList<Album> PhpGalleryUtil::m_all_albums;
+QDict<Album>  PhpGalleryUtil::m_temp_album_dict;
+QDict<Album>  PhpGalleryUtil::m_album_dict;
+int PhpGalleryUtil::m_progress;
+
+
+PhpGalleryUtil::PhpGalleryUtil()
+{
+    m_startURL = gContext->GetSetting("PHPGalleryURL");
+    m_startDir = gContext->GetSetting("GalleryDir");
+    m_refreshCache = gContext->GetNumSetting("PHPGalleryRefreshCache");
+    m_progress = 0;
+    m_stopped = false;
+    
+	QDir dir(m_startDir);
+	if (!dir.exists() || !dir.isReadable())
+	{
+		m_errorStr = tr("MythGallery Directory '%1' does not exist "
+		"or is unreadable.").arg(m_startDir);
+		return;
+	}
+    
+    QString response = MakeRequest("fetch-albums&g2_form%5Bno_perms%5D=yes");
+    if (!response){
+    	m_errorStr += tr("Php Gallery URL '%1' is down or is not correct.").arg(m_startURL);
+    	return;
+    }
+
+    QStringList responseLines = QStringList::split("\n",response);
+    QString albumNumber = NULL;
+    for ( QStringList::Iterator it = responseLines.begin(); it != responseLines.end(); ++it ) 
+    {
+    	QStringList nameList;
+    	QString propValue;
+    	ReadResponseLine(*it, nameList, propValue);
+    	if ((nameList[0].compare("album")==0)&&((nameList.last()).compare(albumNumber)!=0)) 
+    	{
+    		QString albumName=NULL;
+    		QString albumTitle=NULL;
+    		QString albumParent=NULL;	  		
+    		albumNumber = nameList.last();
+    		if (nameList[1].compare("name")==0)
+    		{
+    			albumName = propValue;
+    		}
+        	ReadResponseLine(*++it, nameList, propValue);
+        	if ((nameList[1].compare("title")==0)&&((nameList.last()).compare(albumNumber)==0)) 
+        	{
+        		propValue.replace("/", "-" );
+        		propValue.replace("\\", "-" );
+    			albumTitle = propValue;
+    		}
+        	it++;
+        	ReadResponseLine(*++it, nameList, propValue);
+        	if ((nameList[1].compare("parent")==0)&&((nameList.last()).compare(albumNumber)==0)) 
+        	{
+    			albumParent = propValue;
+    		}
+            if (albumParent.compare("0")==0){
+            	m_rootAlbum = new Album(albumName, albumTitle, albumParent);
+            	m_rootAlbum->SetPath(m_startDir + "/");
+            }
+            else
+            {
+            	Album *album = new Album(albumName, albumTitle, albumParent);
+            	m_all_albums.append(album);
+            	m_temp_album_dict.insert(album->GetName(),album);
+            }
+
+    	}
+    		
+    }
+	QPtrListIterator<Album> it( m_all_albums );
+	Album *thisalbum;
+
+	while ((thisalbum = it.current()) != 0){
+		thisalbum->SetPath(BuildPath(thisalbum,thisalbum->GetTitle()));
+        m_album_dict.insert(thisalbum->GetTitle(),thisalbum);
+		++it;
+	}
+	return;
+}
+
+PhpGalleryUtil::~PhpGalleryUtil()
+{
+    return;
+}
+
+QString PhpGalleryUtil::BuildPath(Album *album, QString path)
+{
+	if (album->GetParent().compare(m_rootAlbum->GetName())==0)
+	{
+		path.prepend(m_startDir + "/");
+		QDir dir(path);
+		if (!dir.exists())
+		{
+			dir.mkdir(path,true);
+		}
+		return path;
+	} 
+	else 
+	{
+		path.prepend(m_temp_album_dict.find(album->GetParent())->GetTitle()+"/");
+		return BuildPath(m_temp_album_dict.find(album->GetParent()),path);
+	}
+}
+		
+
+void PhpGalleryUtil::ReadResponseLine(QString responseLine, QStringList &nameList, QString &propValue)
+{
+	QStringList propertyMap = QStringList::split("=", responseLine);
+	QString propName = propertyMap[0];
+	propValue = propertyMap[1];
+	nameList = QStringList::split(".", propName);
+}
+
+void PhpGalleryUtil::LoadAll(const QString& dir, MythPhpDownloadProgressDialog *dialog)
+{
+	Album *album;
+	if (dir.compare(m_startDir)==0)
+	{
+		album = m_rootAlbum; 
+	} 
+	else 
+	{
+		album = m_album_dict.find(dir.section("/",-1));
+	}
+	GetAll(album, dialog);
+	dialog->setPrimaryProgress(++m_progress);
+	QPtrListIterator<Album> it( m_all_albums );
+	Album *thisalbum;
+
+	while ((thisalbum = it.current()) != 0)
+	{
+		if (m_stopped)
+			return;
+ 		if (thisalbum->GetParent().compare(album->GetName()) == 0)
+ 		{
+ 			LoadAll(thisalbum->GetPath(), dialog);					
+ 		}
+ 		++it;
+	}
+	return;
+}
+
+void PhpGalleryUtil::GetAll(Album *album, MythPhpDownloadProgressDialog *dialog) 
+{
+    int progress = 1;
+    dialog->setSecondaryLabel(album->GetTitle());
+    QString response = MakeRequest("fetch-album-images&g2_form%5Bset_albumName%5D=" + album->GetName());
+    QStringList responseLines = QStringList::split("\n",response);
+    
+    //Find total items in album
+    for ( QStringList::Iterator it = --responseLines.end(); it != responseLines.begin(); --it ) 
+    {
+        if (m_stopped)
+            return;
+        QStringList nameList;
+        QString propValue;
+        ReadResponseLine(*it, nameList, propValue);    
+        if (nameList[0].compare("image_count")==0)
+        {
+            dialog->setSecondaryTotalSteps(propValue.toInt());
+            break;
+        }
+    }
+
+    //Download items in album
+    QString itemNumber = NULL;   
+    for ( QStringList::Iterator it = responseLines.begin(); it != responseLines.end(); ++it ) 
+    {
+        if (m_stopped)
+            return;
+        QStringList nameList;
+        QString propValue;
+        ReadResponseLine(*it, nameList, propValue);
+        if ((nameList[0].compare("image")==0)&&(nameList.last().compare(itemNumber)!=0)) 
+        {
+
+/*            image.name.1=12227
+            image.raw_width.1=3008
+            image.raw_height.1=2000
+            image.raw_filesize.1=1196696
+            image.resizedName.1=12228 if exists
+            image.resized_width.1=640 if exists
+            image.resized_height.1=426 if exists
+            image.thumbName.1=12229
+            image.thumb_width.1=150
+            image.thumb_height.1=100
+            image.forceExtension.1=jpg
+            image.caption.1=DSC_0005.JPG
+            image.title.1=DSC_0005.JPG
+            image.hidden.1=no*/
+
+            QString itemName=NULL;
+            QString thumbName=NULL;
+            QString itemTitle=NULL;
+            QString itemParent=NULL;
+            QString itemExtension=NULL;
+            
+            itemNumber = nameList.last();
+            if (nameList[1].compare("name")==0)
+            {
+                itemName = propValue;
+            }
+            it+=4;
+            ReadResponseLine(*it, nameList, propValue);
+            if (nameList[1].compare("resizedName")==0)
+            {
+                itemName = propValue;
+                it+=3;
+            }
+
+            ReadResponseLine(*it, nameList, propValue);
+            if (nameList[1].compare("thumbName")==0)
+            {
+                thumbName = propValue;
+            }
+            it+=2;
+            ReadResponseLine(*++it, nameList, propValue);
+            if ((nameList[1].compare("forceExtension")==0)&&(nameList.last().compare(itemNumber)==0)) 
+            {
+                itemExtension = propValue;
+            }            
+            ++it;
+            ReadResponseLine(*++it, nameList, propValue);
+            if ((nameList[1].compare("title")==0)&&(nameList.last().compare(itemNumber)==0)) 
+            {
+                itemTitle = propValue;
+            }
+            //make and set QPixmap       
+            QDir dir(album->GetPath());
+            if (!dir.exists())
+                dir.mkdir(album->GetPath());
+            
+            float wmult, hmult;
+            int screenwidth, screenheight;
+            int xbase, ybase;
+            gContext->GetScreenSettings(xbase, screenwidth, wmult, ybase, screenheight, hmult);
+            
+            //Download image
+            QString tempFile= album->GetPath() + "/" + itemTitle;
+            QString url = gContext->GetSetting("PHPGalleryURL")+"?g2_view=core.DownloadItem&g2_itemId="+itemName;
+            if (!QFile::exists(tempFile) || m_refreshCache)
+            {                
+                if (!HttpComms::getHttpFile(tempFile, url, 20000, 3))
+                {
+                    VERBOSE(VB_IMPORTANT, QString("Download Image failed"));                   
+                }
+                VERBOSE(VB_NETWORK, QString("Downloading Image '%1'").arg(tempFile));
+            }
+            //Scale Image
+            QImage image = QImage(tempFile);
+            if (!image.isNull())
+            {
+                image.smoothScale(screenwidth,screenheight,QImage::ScaleMin);
+                image.save(tempFile, "JPEG");
+            }
+            dialog->setSecondaryProgress(progress++);
+        }
+    }
+
+    return;
+}
+
+QString PhpGalleryUtil::MakeRequest(QString cmd){
+    QUrl url = m_startURL;
+    
+    // Make Request to server
+    QByteArray  aBuffer;
+    QTextStream os( aBuffer, IO_WriteOnly );
+    os << "g2_controller=remote%3AGalleryRemote&protocol_version=2.11&g2_form%5Bcmd%5D=";
+    os << cmd;
+    QBuffer buff( aBuffer );
+    QHttpRequestHeader header;
+
+    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, */*" );
+    header.setValue("Accept-Language", "en-us");
+    header.setValue("Content-Type", "application/x-www-form-urlencoded");
+    header.setValue("Connection", "Keep-Alive");
+    header.setValue("Cache-Control", "no-cache");
+
+    QString response  = HttpComms::postHttp( url,
+                                        &header,
+                                        &buff,
+                                        20000, // ms
+                                        3,     // retries
+                                        0,     // redirects
+                                        false, // allow gzip
+                                        NULL,  // login
+                                        true );
+    return response;
+    
+}
+
+Album::Album(QString albumName, QString albumTitle, QString albumParent){
+    m_name = albumName;
+    m_title = albumTitle;
+    m_parent = albumParent;
+}
+
+MythPhpDownloadProgressDialog::MythPhpDownloadProgressDialog(const QString &message, int primaryTotalSteps, int secondaryTotalSteps, 
+                                         bool cancelButton, const QObject *target, const char *slot)
+                  : MythDialog(gContext->GetMainWindow(), "progress", false)
+{
+    int screenwidth, screenheight;
+    float wmult, hmult;
+
+    gContext->GetScreenSettings(screenwidth, wmult, screenheight, hmult);
+
+    setFont(gContext->GetMediumFont());
+
+    gContext->ThemeWidget(this);
+
+    int yoff = screenheight / 3;
+    int xoff = screenwidth / 10;
+    setGeometry(xoff, yoff, screenwidth - xoff * 2, yoff);
+    setFixedSize(QSize(screenwidth - xoff * 2, yoff));
+
+    QVBoxLayout *lay = new QVBoxLayout(this, 0);
+
+    QVBox *vbox = new QVBox(this);
+    lay->addWidget(vbox);
+
+    vbox->setLineWidth(3);
+    vbox->setMidLineWidth(3);
+    vbox->setFrameShape(QFrame::Panel);
+    vbox->setFrameShadow(QFrame::Raised);
+    vbox->setMargin((int)(15 * wmult));
+
+    primarymsglabel = new QLabel(vbox);
+    primarymsglabel->setBackgroundOrigin(ParentOrigin);
+    primarymsglabel->setText(message);
+    vbox->setStretchFactor(primarymsglabel, 5);
+
+    QHBox *hbox = new QHBox(vbox);
+    hbox->setSpacing(5);
+    
+    primaryProgress = new QProgressBar(primaryTotalSteps, hbox);
+    primaryProgress->setBackgroundOrigin(ParentOrigin);
+    
+    secondarymsglabel = new QLabel(vbox);
+    secondarymsglabel->setBackgroundOrigin(ParentOrigin);
+    vbox->setStretchFactor(secondarymsglabel, 5);
+    QHBox *shbox = new QHBox(vbox);
+    shbox->setSpacing(5);
+    
+    secondaryProgress = new QProgressBar(secondaryTotalSteps, shbox);
+    secondaryProgress->setBackgroundOrigin(ParentOrigin);
+   
+    if (cancelButton && slot && target)
+    {
+        MythPushButton *button = new MythPushButton("Cancel", vbox, 0);
+        button->setFocus();
+        connect(button, SIGNAL(pressed()), target, slot);
+    }
+
+    setPrimaryTotalSteps(primaryTotalSteps);
+    setSecondaryTotalSteps(secondaryTotalSteps);
+    
+    if (class LCD * lcddev = LCD::Get())
+    {
+        textItems = new QPtrList<LCDTextItem>;
+        textItems->setAutoDelete(true);
+
+        textItems->clear();
+        textItems->append(new LCDTextItem(1, ALIGN_CENTERED, message, "Generic",
+                          false));
+        lcddev->switchToGeneric(textItems);
+    }
+    else 
+        textItems = NULL;
+
+    show();
+
+    qApp->processEvents();
+}
+
+MythPhpDownloadProgressDialog::~MythPhpDownloadProgressDialog()
+{
+    Teardown();
+}
+
+void MythPhpDownloadProgressDialog::deleteLater(void)
+{
+    hide();
+    Teardown();
+    MythDialog::deleteLater();
+}
+
+void MythPhpDownloadProgressDialog::Teardown(void)
+{
+    if (textItems)
+    {
+        delete textItems;
+        textItems = NULL;
+    }
+}
+
+void MythPhpDownloadProgressDialog::Close(void)
+{
+    accept();
+
+    LCD *lcddev = LCD::Get();
+    if (lcddev)
+    {
+        lcddev->switchToNothing();
+        lcddev->switchToTime();
+    }
+}
+
+void MythPhpDownloadProgressDialog::setPrimaryProgress(int curprogress)
+{
+    primaryProgress->setProgress(curprogress);
+    if (curprogress % primarySteps == 0)
+    {
+        qApp->processEvents();
+        if (LCD * lcddev = LCD::Get())
+        {
+            float fProgress = (float)curprogress / m_primaryTotalSteps;
+            lcddev->setGenericProgress(fProgress);
+        }
+    }
+}
+
+void MythPhpDownloadProgressDialog::setSecondaryProgress(int curprogress)
+{
+    secondaryProgress->setProgress(curprogress);
+    if (curprogress % secondarySteps == 0)
+    {
+        qApp->processEvents();
+    }
+}
+
+void MythPhpDownloadProgressDialog::setPrimaryLabel(QString newlabel)
+{
+    primarymsglabel->setText(newlabel);
+}
+
+void MythPhpDownloadProgressDialog::setSecondaryLabel(QString newlabel)
+{
+    secondarymsglabel->setText(newlabel);
+}
+
+void MythPhpDownloadProgressDialog::keyPressEvent(QKeyEvent *e)
+{
+    bool handled = false;
+    QStringList actions;
+    if (gContext->GetMainWindow()->TranslateKeyPress("qt", e, actions))
+    {
+        for (unsigned int i = 0; i < actions.size() && !handled; i++)
+        {
+            QString action = actions[i];
+            if (action == "ESCAPE")
+                handled = true;
+        }
+    }
+
+    if (!handled)
+        MythDialog::keyPressEvent(e);
+}
+
+void MythPhpDownloadProgressDialog::setPrimaryTotalSteps(int totalSteps)
+{
+    m_primaryTotalSteps = totalSteps;
+    primaryProgress->setTotalSteps(totalSteps);
+    primarySteps = totalSteps / 1000;
+    if (primarySteps == 0)
+        primarySteps = 1;
+}
+
+void MythPhpDownloadProgressDialog::setSecondaryTotalSteps(int totalSteps)
+{
+    m_secondaryTotalSteps = totalSteps;
+    secondaryProgress->setTotalSteps(totalSteps);
+    secondarySteps = totalSteps / 1000;
+    if (secondarySteps == 0)
+    	secondarySteps = 1;
+}
Index: mythgallery/mythgallery/phpgalleryutil.h
===================================================================
--- mythgallery/mythgallery/phpgalleryutil.h	(revision 0)
+++ mythgallery/mythgallery/phpgalleryutil.h	(revision 0)
@@ -0,0 +1,115 @@
+//
+// C++ Interface: PhpGalleryUtil
+//
+// Description: 
+//
+//
+// Author: mythtv <mythtv@jshoor-media>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <qstringlist.h>
+#include <qbuffer.h>
+#include <mythtv/httpcomms.h>
+#include <mythtv/mythdialogs.h>
+class  MythPhpDownloadProgressDialog;
+
+class Album
+{
+public:
+	Album(QString albumName, QString albumTitle, QString albumParent);
+	QString GetName(){return m_name;}
+	QString GetTitle(){return m_title;}
+	QString GetParent(){return m_parent;}
+	QString GetPath(){return m_path;}
+	void SetPath(QString path){m_path = path;}
+private:
+	QString m_name;
+	QString m_title;
+	QString m_parent;
+	QString m_path;
+};
+
+
+class PhpGalleryUtil : QObject
+{
+ Q_OBJECT
+ public:
+	PhpGalleryUtil();
+	~PhpGalleryUtil();
+	void LoadAll(const QString& dir,  MythPhpDownloadProgressDialog *dialog);
+	void GetAll(Album *album, MythPhpDownloadProgressDialog *dialog);
+
+	Album *GetRootAlbum(){return m_rootAlbum;}
+	int GetAlbumCount(){return m_all_albums.count();}
+    QString GetError() { return m_errorStr; }
+    void Stop(){ m_stopped = true; return;}
+
+    
+ private:
+ void ReadResponseLine(QString responseLine, QStringList &nameList, QString &propValue);
+ QString MakeRequest(QString cmd);
+ QString BuildPath(Album *album, QString path);
+ static QString m_startURL;
+ static QString m_startDir;
+ static Album *m_rootAlbum;
+ static int m_refreshCache;
+ static QPtrList<Album> m_all_albums;
+ static QDict<Album>  m_temp_album_dict;
+ static QDict<Album>  m_album_dict;
+ static int m_progress;
+ QString m_errorStr;
+ bool m_stopped;
+};
+
+class MPUBLIC MythPhpDownloadProgressDialog: public MythDialog
+{
+    Q_OBJECT
+  public:
+    MythPhpDownloadProgressDialog(const QString& message, int primaryTotalSteps = 0, int secondaryTotalSteps = 0, 
+                       bool cancelButton = false, 
+                       const QObject * target = NULL, 
+                       const char * slot = NULL);
+
+    void Close(void);
+
+    void setPrimaryProgress(int curprogress);
+    void setSecondaryProgress(int curprogress);
+    
+    void setPrimaryLabel(QString newlabel);
+    void setSecondaryLabel(QString newlabel);
+    
+    void keyPressEvent(QKeyEvent *);
+
+    virtual void deleteLater(void);
+    void setSecondaryTotalSteps(int totalSteps);
+    
+  signals:
+    void pressed();
+
+  protected:
+    void Teardown(void);
+    ~MythPhpDownloadProgressDialog(); 
+    QProgressBar *primaryProgress;
+    QProgressBar *secondaryProgress;
+    QLabel *primarymsglabel;
+    QLabel *secondarymsglabel;
+    
+  private:
+    void setPrimaryTotalSteps(int totalSteps);
+
+    int primarySteps;
+    int m_primaryTotalSteps;
+    int secondarySteps;
+    int m_secondaryTotalSteps;
+    QPtrList<class LCDTextItem> * textItems;
+};
+
+
+
+
+
+
+
Index: mythgallery/mythgallery/mythgallery.pro
===================================================================
--- mythgallery/mythgallery/mythgallery.pro	(revision 15270)
+++ mythgallery/mythgallery/mythgallery.pro	(working copy)
@@ -29,11 +29,13 @@
 HEADERS += qtiffio.h           galleryutil.h
 HEADERS += constants.h
 HEADERS += thumbgenerator.h    thumbview.h
+HEADERS += phpgalleryutil.h
 SOURCES += iconview.cpp        singleview.cpp
 SOURCES += imageview.cpp
 SOURCES += gallerysettings.cpp dbcheck.cpp
 SOURCES += qtiffio.cpp         galleryutil.cpp
 SOURCES += thumbgenerator.cpp  thumbview.cpp
+SOURCES += phpgalleryutil.cpp
 SOURCES += main.cpp
 
 opengl {
Index: mythgallery/mythgallery/gallerysettings.cpp
===================================================================
--- mythgallery/mythgallery/gallerysettings.cpp	(revision 15270)
+++ mythgallery/mythgallery/gallerysettings.cpp	(working copy)
@@ -34,6 +34,34 @@
     return gc;
 };
 
+static HostCheckBox *MythGalleryUsePHPGallery()
+{
+    HostCheckBox *gc = new HostCheckBox("UsePHPGallery");
+    gc->setLabel(QObject::tr("Use PHP Gallery"));
+    gc->setValue(false);
+    gc->setHelpText(QObject::tr("Check this to enable a "
+                                "remote PHP Gallery Installation"));
+    return gc;
+};
+
+static HostLineEdit *MythGalleryPHPGalleryURL()
+{
+    HostLineEdit *gc = new HostLineEdit("PHPGalleryURL");
+    gc->setLabel(QObject::tr("URL of PHP Gallery"));
+    gc->setValue(QObject::tr("http://www.mygallery.com/gallery2/main.php"));
+    gc->setHelpText(QObject::tr("For example: http://www.mygallery.com/gallery2/main.php"));
+    return gc;
+};
+
+static HostCheckBox *MythGalleryRefreshPHPGalleryCache()
+{
+	HostCheckBox *gc = new HostCheckBox("PHPGalleryRefreshCache");
+    gc->setLabel(QObject::tr("Overwrite Existing Images"));
+    gc->setValue(false);
+    gc->setHelpText(QObject::tr("Overwrite existing Images. This will slow load time significantly."));
+    return gc;
+};
+
 static HostComboBox *MythGallerySortOrder()
 {
     HostComboBox *gc = new HostComboBox("GallerySortOrder");
@@ -208,18 +236,36 @@
 
 };
 
+GeneralGalleryConfigurationGroup::GeneralGalleryConfigurationGroup() :
+        TriggeredConfigurationGroup(false, true, false, false)
+{
+        setLabel(QObject::tr("MythGallery Settings (General)"));
+        setUseLabel(false);
+        addChild(MythGalleryDir());
+        addChild(MythGalleryThumbnailLocation());
+        addChild(MythGallerySortOrder());
+        addChild(MythGalleryImportDirs());
+        addChild(MythGalleryMoviePlayerCmd());
 
+        HostCheckBox* usePHPGallery = MythGalleryUsePHPGallery();
+        addChild(usePHPGallery);
+        setTrigger(usePHPGallery);
+
+        ConfigurationGroup* PHPConfig = new VerticalConfigurationGroup(false);
+        PHPConfig->addChild(MythGalleryPHPGalleryURL());
+        PHPConfig->addChild(MythGalleryRefreshPHPGalleryCache());
+        addTarget("1", PHPConfig); 
+        ConfigurationGroup* regularConfig = new VerticalConfigurationGroup(false);
+        addTarget("0", regularConfig);
+}
+
+
 GallerySettings::GallerySettings()
 {
-    VerticalConfigurationGroup* general = new VerticalConfigurationGroup(false);
-    general->setLabel(QObject::tr("MythGallery Settings (General)"));
-    general->addChild(MythGalleryDir());
-    general->addChild(MythGalleryThumbnailLocation());
-    general->addChild(MythGallerySortOrder());
-    general->addChild(MythGalleryImportDirs());
-    general->addChild(MythGalleryMoviePlayerCmd());
-    addChild(general);
 
+    GeneralGalleryConfigurationGroup* generalConfig = new GeneralGalleryConfigurationGroup();
+    addChild(generalConfig);
+
     GalleryConfigurationGroup* config = new GalleryConfigurationGroup();
     addChild(config);
 }
Index: mythgallery/mythgallery/iconview.cpp
===================================================================
--- mythgallery/mythgallery/iconview.cpp	(revision 15270)
+++ mythgallery/mythgallery/iconview.cpp	(working copy)
@@ -1218,6 +1218,11 @@
     item = new UIListBtnTypeItem(m_submenuType, tr("Show Devices"));
     item->setData(new MenuAction(&IconView::HandleShowDevices));
 
+    if(gContext->GetSetting("UsePHPGallery").compare("1")==0){
+        item = new UIListBtnTypeItem(m_submenuType, tr("Download"));
+        item->setData(new MenuAction(&IconView::HandleDownload));
+    }
+
     item = new UIListBtnTypeItem(m_submenuType, tr("Import"));
     item->setData(new MenuAction(&IconView::HandleImport));
 
@@ -1403,6 +1408,50 @@
     }
 }
 
+void IconView::HandleDownload(void)
+{
+    DialogBox *downloadDlg = new DialogBox(
+        gContext->GetMainWindow(), tr("Download pictures from '%1'?").arg(gContext->GetSetting("PHPGalleryURL")));
+
+    downloadDlg->AddButton(tr("No"));
+    downloadDlg->AddButton(tr("Yes"));
+    DialogCode code = downloadDlg->exec();
+    downloadDlg->deleteLater();
+    if (kDialogCodeButton1 != code)
+        return;
+    MythBusyDialog *busy = new MythBusyDialog(
+        QObject::tr("Attempting to download files."));
+
+    busy->start(); 
+    m_phpGalleryUtil = new PhpGalleryUtil();   
+    busy->Close();
+    busy->deleteLater();
+    if (m_phpGalleryUtil->GetError().isEmpty())
+    {
+        m_dialog = new MythPhpDownloadProgressDialog(
+            QObject::tr("Downloading images"), m_phpGalleryUtil->GetAlbumCount(), 0, true, this, SLOT(cancelDownload()));
+        QPtrList<ThumbItem> mythumblist;
+        QTime t;
+        t.start();
+        m_phpGalleryUtil->LoadAll(gContext->GetSetting("GalleryDir"), m_dialog);
+        VERBOSE(VB_IMPORTANT, QString("Finished Loading Pictures in '%1' secs").arg(t.elapsed()/1000));
+        m_dialog->Close();
+        m_dialog->deleteLater();
+    }
+    else 
+    {
+        DialogBox *dlg = new DialogBox(
+            gContext->GetMainWindow(), m_phpGalleryUtil->GetError());
+
+        dlg->AddButton(QObject::tr("Ok"));
+        dlg->exec();
+        dlg->deleteLater();
+        return;
+    }
+    LoadDirectory(gContext->GetSetting("GalleryDir"), true);
+
+}
+
 void IconView::HandleShowDevices(void)
 {
 #ifndef _WIN32
@@ -1689,3 +1738,17 @@
         UpdateText();
     }
 }
+
+void IconView::cancelDownload()
+{
+    DialogBox *downloadDlg = new DialogBox(
+        gContext->GetMainWindow(), tr("Are you sure you want to cancel downloading?"));
+
+    downloadDlg->AddButton(tr("No"));
+    downloadDlg->AddButton(tr("Yes"));
+    DialogCode code = downloadDlg->exec();
+    downloadDlg->deleteLater();
+    if (kDialogCodeButton1 != code)
+        return;
+    m_phpGalleryUtil->Stop(); 
+}
Index: mythgallery/mythgallery/gallerysettings.h
===================================================================
--- mythgallery/mythgallery/gallerysettings.h	(revision 15270)
+++ mythgallery/mythgallery/gallerysettings.h	(working copy)
@@ -4,6 +4,12 @@
 #include "mythtv/settings.h"
 #include "mythtv/mythcontext.h"
 
+class GeneralGalleryConfigurationGroup : public TriggeredConfigurationGroup
+{
+  public:
+    GeneralGalleryConfigurationGroup();
+};
+
 class GallerySettings : public ConfigurationWizard
 {
   public:  
Index: mythgallery/mythgallery/iconview.h
===================================================================
--- mythgallery/mythgallery/iconview.h	(revision 15270)
+++ mythgallery/mythgallery/iconview.h	(working copy)
@@ -28,6 +28,7 @@
 
 // MythGallery headers
 #include "thumbview.h"
+#include "phpgalleryutil.h"
 
 class XMLParse;
 class UIListBtnType;
@@ -101,6 +102,7 @@
     void HandleSelectAll(void);
     void HandleMkDir(void);
     void HandleRename(void);
+    void HandleDownload(void);
 
     void HandleMenuButtonPress(void);
 
@@ -114,7 +116,7 @@
     QDict<ThumbItem>    m_itemDict;
     QStringList         m_itemMarked;
     QString             m_galleryDir;
-
+    
     XMLParse           *m_theme;
     QRect               m_menuRect;
     QRect               m_textRect;
@@ -160,11 +162,14 @@
     QStringList         m_paths;
 
     QString             m_errorStr;
+    PhpGalleryUtil 		*m_phpGalleryUtil;
+    MythPhpDownloadProgressDialog *m_dialog;
 
     typedef void (IconView::*MenuAction)(void);
 
   public slots:
     void mediaStatusChanged(MediaStatus oldStatus, MythMediaDevice *pMedia);
+    void cancelDownload();
 };
 
 
