#include "ui_bookScanner.h"
#include "Scheduler.h"
#include "WatchUdev.h"
#include "ConfigDialog.h"

class WrapGphoto2;

class BookScanner : public QDialog {

   Q_OBJECT

public:

   BookScanner();

   ~BookScanner();

private slots:

      // Click button was pushed.
      //
   void
   doClick();

      // Invoked when UDEV devices are plugged or unplugged. Matches the
      // properties to see if this is a camera of interest.
      //
   void
   devPlug(QString action,
           QString path,
           QString subsystem,
           QMap<QString, QString> properties);

      // Navigate through the image directories, changing preview images.
      //
   void
   navigatePictures();

      // Zero length timeout used to trigger scan of existing udev
      // devices after BookScanner is fully constructed.
      //
   void
   runScan();

      // Pop up config dialog (creating it the first time it is called).
      //
   void
   doConfig();

      // Have to run the resize in a zero length timeout so the layouts
      // get updated before I try to resize them.
      //
   void
   resizeMe();

      // Connect to light always on checkbox
      //
   void
   doLightCheck(int new_state);

private:

   enum WhichSubdir {
      SUBDIR_LEFT,
      SUBDIR_RIGHT
   };

   enum NavigateDirection {
      FIRST_IMAGE,
      LAST_IMAGE,
      NEXT_IMAGE,
      PREV_IMAGE,
   };

   void
   openScheduler(QString devname);

   void
   fetchPictures(QString bus,
                 QString dev,
                 QString srcdir,
                 QString destdir);

   void
   updateImages(QString dirname);

   void
   updateLeftImage(QString name);

   void
   updateRightImage(QString name);

   void
   logTime(QString msg);

   QString
   LeftCameraDestDirectory();

   QString
   RightCameraDestDirectory();

   void
   doNavigate(WhichSubdir dir, NavigateDirection nav);

   void
   updateImageSize(QSize new_size);

   void
   StartProgram(const ProgramEntryList & prog);

   Ui::bookScanner ui;

   Scheduler * sched;

   WatchUdev * watch_udev;

   QString last_left_image;
   QString last_right_image;

   ConfigDialog * config_dialog;

   WrapGphoto2 * wgp;

   int click_count;
};
