Browse Source

added homepage, shortcuts, multi-album, custom timeout

gwillz 6 years ago
parent
commit
2fc166a189
11 changed files with 134 additions and 53 deletions
  1. 3 0
      FBSlideshow.pro
  2. BIN
      black.png
  3. 56 15
      dialogs.cpp
  4. 5 0
      dialogs.h
  5. 17 13
      fbApi.cpp
  6. 2 2
      fbApi.h
  7. BIN
      homepage.png
  8. BIN
      homepage.psd
  9. 6 0
      resources.qrc
  10. 41 23
      slidewindow.cpp
  11. 4 0
      slidewindow.h

+ 3 - 0
FBSlideshow.pro

@@ -23,3 +23,6 @@ SOURCES += main.cpp\
 HEADERS  += slidewindow.h \
             fbApi.h \
     dialogs.h
+
+RESOURCES += \
+    resources.qrc

BIN
black.png


+ 56 - 15
dialogs.cpp

@@ -5,9 +5,9 @@ LoginDialog::LoginDialog(QWidget *parent)
         : QDialog(parent) {
     
     //housekeeping
-    setFixedHeight(200);
-    setFixedWidth(300);
     setWindowTitle("Login to Facebook");
+    setFixedWidth(300);
+    setFixedHeight(150);
     QFormLayout *layout = new QFormLayout(this);
     setLayout(layout);
     
@@ -15,21 +15,32 @@ LoginDialog::LoginDialog(QWidget *parent)
     
     userEdit = new QLineEdit(st.value("user").toString(), this);
     passEdit = new QLineEdit(st.value("pass").toString(), this);
+    timeEdit = new QSpinBox(this);
+    
     passEdit->setEchoMode(QLineEdit::Password);
+    timeEdit->setMaximum(100000);
+    timeEdit->setMinimum(500);
+    timeEdit->setValue(st.value("timeout").toLongLong());
+    
+    qDebug() << st.value("timeout").toInt();
     
     QPushButton *okButton = new QPushButton("Login", this);
-    okButton->setMaximumWidth(70);
     QPushButton *exitButton = new QPushButton("Cancel", this);
+    okButton->setMaximumWidth(70);
     exitButton->setMaximumWidth(70);
     
+    QHBoxLayout *buttons = new QHBoxLayout(this);
+    buttons->addStretch();
+    buttons->addWidget(okButton);
+    buttons->addWidget(exitButton);
+    
     layout->addRow("Username:", userEdit);
     layout->addRow("Password:", passEdit);
-    layout->addWidget(okButton);
-    layout->addWidget(exitButton);
-    
+    layout->addRow("Timeout:", timeEdit);
+    layout->addRow(buttons);
     
     connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
-    connect(exitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
+    connect(exitButton, SIGNAL(clicked()), this, SLOT(exitClicked()));
     
 }
 
@@ -38,11 +49,17 @@ void LoginDialog::okClicked() {
     
     st.setValue("user", userEdit->text());
     st.setValue("pass", passEdit->text());
+    st.setValue("timeout", timeEdit->value());
     st.sync();
     
     hide();
 }
 
+void LoginDialog::exitClicked() {
+    qApp->quit();
+    hide();
+}
+
 AlbumDialog::AlbumDialog(QWidget *parent) 
         : QDialog(parent) {
     
@@ -70,29 +87,52 @@ AlbumDialog::AlbumDialog(QWidget *parent)
     QPushButton *exitButton = new QPushButton("Cancel", this);
     exitButton->setMaximumWidth(70);
     
-    layout->addWidget(list);
-    layout->addWidget(okButton);
-    layout->addWidget(exitButton);
+    QHBoxLayout *buttons = new QHBoxLayout(this);
+    buttons->addStretch();
+    buttons->addWidget(okButton);
+    buttons->addWidget(exitButton);
     
+    layout->addWidget(list);
+    layout->addLayout(buttons);
     
     connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
     connect(exitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
-    connect(list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(okClicked()));
+    //connect(list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(okClicked()));
 }
 
 void AlbumDialog::okClicked() {
-    aid = list->currentItem()->data(Qt::UserRole).toString();
+    qDebug() << "registering albums";
+    
+    QStringList checked;
+    for (int i=0; i<list->count(); i++) {
+        QListWidgetItem *item = list->item(i);
+        
+        if (item->checkState() == Qt::Checked) {
+            checked.append(item->data(Qt::UserRole).toString());
+            qDebug() << "id: " << item->data(Qt::UserRole).toString();
+        }
+    }
     
-    qDebug() << "registering album: " << list->currentItem()->text();
-    qDebug() << "id: " << aid;
+    
+    //old magic
+    //aid = list->currentItem()->data(Qt::UserRole).toString();
+    
+    //qDebug() << "registering albums: " << list->currentItem()->text();
+    //qDebug() << "id: " << aid;
     
     QSettings st("GwillzCorp", "fbslideshow");
-    st.setValue("album", aid);
+    //st.setValue("album", aid);
+    st.setValue("albums", checked);
     st.sync();
     
     hide();
 }
 
+void AlbumDialog::exitClicked() {
+    qApp->quit();
+    hide();
+}
+
 void AlbumDialog::loggedIn() {
     fb->getAlbumsId();
 }
@@ -101,6 +141,7 @@ void AlbumDialog::loadAlbums() {
     foreach (QVariantMap album, fb->albumList) {
         QListWidgetItem *item = new QListWidgetItem(album.value("name").toString());
         item->setData(Qt::UserRole, album.value("aid").toString());
+        item->setCheckState(Qt::Unchecked);
         list->addItem(item);
     }
 }

+ 5 - 0
dialogs.h

@@ -3,6 +3,7 @@
 
 #include <QDialog>
 class QLineEdit;
+class QSpinBox;
 
 class LoginDialog 
         : public QDialog {
@@ -10,6 +11,7 @@ class LoginDialog
     
     QLineEdit *userEdit;
     QLineEdit *passEdit;
+    QSpinBox *timeEdit;
     
     public:
         explicit LoginDialog(QWidget *parent = 0);
@@ -18,6 +20,7 @@ class LoginDialog
         
     public slots:
         void okClicked();
+        void exitClicked();
 };
 #endif // LOGINDIALOG_H
 
@@ -44,6 +47,8 @@ class AlbumDialog
         
     public slots:
         void okClicked();
+        void exitClicked();
+        
         void loadAlbums();
         void loggedIn();
 };

+ 17 - 13
fbApi.cpp

@@ -21,6 +21,7 @@ FbApi::FbApi(QObject * parent)
     
     //housekeeping
     net = new QNetworkAccessManager(this);
+    page = new QWebPage(this);
 
     //defaults
     id = "";
@@ -31,7 +32,6 @@ FbApi::FbApi(QObject * parent)
     picList = new QStringList(st.value("images").toStringList());
     user = new QString(st.value("user").toString());
     pass = new QString(st.value("pass").toString());
-    page = new QWebPage(this);
     
     //events
     connect(page, SIGNAL(loadFinished(bool)), this, SLOT(doAuthentication(bool)));
@@ -41,21 +41,18 @@ void FbApi::authenticate() {
     qDebug() << "authenticating";
     
     page->mainFrame()->load(QUrl(getLoginUrl()));
-    //QDesktopServices::openUrl(page->mainFrame()->url());
+    //QDesktopServices::openUrl(page->mainFrame()->url()); //eh?
 }
 
 void FbApi::doAuthentication(bool stat) {
     if (stat) {
-        qDebug() << page->mainFrame()->url().toString();
+        //qDebug() << page->mainFrame()->url().toString();
         
         QUrl url = QUrl(page->mainFrame()->url().toString().replace("#access_token", "?access_token"));
         
         if (url.hasQueryItem("access_token")){
             qDebug() << "success";
-            
-            //qDebug() << "Yei: \n\n";
-            qDebug() << url.queryItemValue("access_token");
-            //qDebug() << *pass;
+            //qDebug() << url.queryItemValue("access_token");
             
             token = url.queryItemValue("access_token");
             //getPicsId();
@@ -88,7 +85,16 @@ void FbApi::getPicsId() {
     
     QString url = QString(getAlbumPics);
     url.replace("ACCESS_TOKEN", token, Qt::CaseSensitive);
-    url.replace("ALBUM_ID", aid, Qt::CaseSensitive);
+    
+    QString albumString = tr("aid=\"%1\"").arg(aid.takeFirst());
+    
+    foreach (QString a, aid) {
+        albumString += tr("or aid=\"%1\"").arg(a);
+    }
+    
+    url.replace("ALBUM_IDS", albumString, Qt::CaseSensitive);
+    
+    qDebug() << url;
     
     resp = net->get(QNetworkRequest(QUrl(url)));
     connect(resp, SIGNAL(finished()), this, SLOT(loadPicList()));
@@ -125,7 +131,7 @@ void FbApi::loadPicList() {
             picList->append(pic.toMap()["src_big"].toString());
         }
         
-        qDebug() << picList->count() << " photo(s)";
+        qDebug() << picList->count() << "photo(s)";
         
         QSettings st(company_str, app_str);
         st.setValue("images", *picList);
@@ -157,16 +163,14 @@ void FbApi::loadAlbumList() {
     //delete resp;
 
     if (ok) {
+        albumList.clear();
         qDebug() << "loading albums";
         
         foreach (QVariant album, result.toMap()["data"].toList()) {
             albumList.append(album.toMap());
         }
         
-        qDebug() << albumList.count() << " album(s)";
-        
-        //QSettings st(company_str, app_str);
-        //st.setValue("albums", *albumList);
+        qDebug() << albumList.count() << "album(s)";
         
         emit albumsLoaded();
     }

+ 2 - 2
fbApi.h

@@ -14,7 +14,7 @@
 #define getTagPics "https://graph.facebook.com/fql?q=SELECT+src_big+FROM+photo+WHERE+pid+IN+(SELECT+pid+FROM+photo_tag+WHERE+subject=me())&access_token=ACCESS_TOKEN"
 
 #define getAlbums "https://graph.facebook.com/fql?q=SELECT+aid,+name+FROM+album+WHERE+owner=me()&access_token=ACCESS_TOKEN"
-#define getAlbumPics "https://graph.facebook.com/fql?q=SELECT+src_big+FROM+photo+WHERE+aid+=+\"ALBUM_ID\"&access_token=ACCESS_TOKEN"
+#define getAlbumPics "https://graph.facebook.com/fql?q=SELECT+src_big+FROM+photo+WHERE+ALBUM_IDS&access_token=ACCESS_TOKEN"
 
 #define company_str "GwillzCorp"
 #define app_str "fbslideshow"
@@ -33,7 +33,7 @@ class FbApi
         QStringList *picList;
         void getPicsId();
         
-        QString aid;
+        QStringList aid;
         QList<QVariantMap> albumList;
         void getAlbumsId();
         

BIN
homepage.png


BIN
homepage.psd


+ 6 - 0
resources.qrc

@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/img">
+        <file>homepage.png</file>
+        <file>black.png</file>
+    </qresource>
+</RCC>

+ 41 - 23
slidewindow.cpp

@@ -1,8 +1,6 @@
 #include "slidewindow.h"
 #include <QtGui>
 
-#define timeout 5000
-
 SlideWindow::SlideWindow(QWidget *parent)
         : QMainWindow(parent) {
     
@@ -14,8 +12,8 @@ SlideWindow::SlideWindow(QWidget *parent)
     setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
     setPalette(QPalette(QColor().black()));
     
-    //set pixmap
-    QPixmap pix("G:\\Lincoln Snapshots\\squire.jpg");
+    //set default pixmap
+    QPixmap pix(":/img/homepage.png");
     pix = pix.scaled(this->width(), this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
     
     //set label widget
@@ -27,44 +25,67 @@ SlideWindow::SlideWindow(QWidget *parent)
     setCentralWidget(img);
     
     //set keyboard shortcuts
-    QAction *escAction = new QAction("&Quit", this);
-    escAction->setShortcut(tr("ESC"));
-    
-    //menuBar()->addAction(escAction);
+    QAction *escAction = new QAction(this);
+    QAction *pauseAction = new QAction(this);
+    QAction *blankAction = new QAction(this);
+    escAction->setShortcut(Qt::Key_Escape);
+    pauseAction->setShortcut(Qt::Key_Space);
+    blankAction->setShortcut(Qt::Key_Return);
     
-    //QMenu *fileMenu = new QMenu("&File", this);
-    //fileMenu->addAction(escAction);
-    //connect(this, SIGNAL(customContextMenuRequested(QPoint), this, eh?);
+    addAction(escAction);
+    addAction(pauseAction);
+    addAction(blankAction);
     
-    //setContextMenuPolicy(Qt::CustomContextMenu);
-    //connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT());
-    
-    //open config dialog
+    //open login dialog
     loginDiag = new LoginDialog(this);
     loginDiag->exec();
     
+    //open album dialog
     albumDiag = new AlbumDialog(this);
     albumDiag->exec();
     
+    //load settings
+    QSettings st("GwillzCorp", "fbslideshow");
+    timeout = st.value("timeout").toInt();
+    
     //timer
     timer = new QTimer();
-    timer->start(timeout);
     
-    //fb test
-    QSettings st("GwillzCorp", "fbslideshow");
+    //fb stuff
     fb = new FbApi(this);
-    fb->id = "317511414947451";
-    fb->aid = st.value("album").toString();
+    fb->id = "317511414947451"; //TODO: change to #define value
+    fb->aid = st.value("albums").toStringList();
     fb->saveCredentials(st.value("user").toString(), st.value("pass").toString());
     
     //events
     connect(escAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+    connect(pauseAction, SIGNAL(triggered()), this, SLOT(pause()));
+    connect(blankAction, SIGNAL(triggered()), this, SLOT(blank()));
     connect(timer, SIGNAL(timeout()), this, SLOT(photoChange()));
     connect(fb, SIGNAL(picsLoaded()), this, SLOT(photoChange()));
     connect(fb, SIGNAL(picLoaded(QString*)), this, SLOT(setImage(QString*)));
     connect(fb, SIGNAL(loginResult(bool)), this, SLOT(loggedIn()));
     
+    //do it!
     fb->authenticate();
+    
+    qDebug() << "slideshow started with a" << timeout << "ms timeout";
+    
+}
+
+void SlideWindow::pause() {
+    if (timer->isActive()) {
+        qDebug() << "paused";
+        timer->stop();
+    } else {
+        qDebug() << "unpaused";
+        photoChange();
+    }
+}
+
+void SlideWindow::blank() {
+    pause();
+    img->setPixmap(QPixmap(":/img/black.png"));
 }
 
 void SlideWindow::photoChange() {
@@ -75,9 +96,6 @@ void SlideWindow::photoChange() {
 }
 
 void SlideWindow::setImage(QString *path) {
-    //qDebug() << size();
-    
-    //QPixmap pix("G:\\Lincoln Snapshots\\ed.jpg");
     QPixmap pix(*path);
     pix = pix.scaled(this->width(), this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
     

+ 4 - 0
slidewindow.h

@@ -12,6 +12,8 @@ class SlideWindow
         : public QMainWindow {
     Q_OBJECT
     
+    int timeout;
+    
     QLabel *img;
     QTimer *timer;
     FbApi *fb;
@@ -25,6 +27,8 @@ class SlideWindow
         void photoChange();
         void setImage(QString *path);
         void loggedIn();
+        void pause();
+        void blank();
 };
 
 #endif // SLIDEWINDOW_H