/***************************************************************************
 *   Copyright (C) 2025 by David C. Rankin                                      *
 *   david@niflheim                                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#include "kgenericbacklight.h"

#include <kuniqueapplication.h>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>

#include <qsize.h>

#include <qimage.h>
#include <qpixmap.h>

#define AMD_ICON          "/usr/local/share/pixmaps/amd-logo-64.png"
#define INTEL_ICON        "/usr/local/share/pixmaps/intel-64x64.png"
#define INTEL_WH_ICON     "/usr/local/share/pixmaps/intel-64-white.png"
#define NVIDIA_ICON       "/usr/local/share/pixmaps/nvidia-64.png"
#define KDE_ICON          "/usr/local/share/pixmaps/kdebacklight-64.png"
#define KDE_ON_ICON       "/usr/local/share/pixmaps/kdebacklight-on-64.png"

static const char description[] =
    I18N_NOOP("A KDE Display Backlight Application");

static const char version[] = "0.1";

static KCmdLineOptions options[] =
{
//  { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
  KCmdLineLastOption
};

int main(int argc, char **argv)
{
  KAboutData about ("KDE Backlight", I18N_NOOP("KDE Backlight"), version, description,
                    KAboutData::License_GPL, "(C) 2025 David C. Rankin", 0, 0, "david@niflheim");
  about.addAuthor ("David C. Rankin", 0, "david@niflheim");
  KCmdLineArgs::init(argc, argv, &about);
  KCmdLineArgs::addCmdLineOptions (options);
  KUniqueApplication app;
  kgenericbacklight *mainWin = 0;
  QSize mainWinSz (320, 130);

  bool haveicon = false;
  QImage img;
  QPixmap icon;
  // if (img.load (INTEL_ICON, "PNG")) {
  // if (img.load (KDE_ON_ICON, "PNG")) {
  if (img.load (KDE_ICON, "PNG")) {
    icon = img;
    haveicon = true;
  }

  if (app.isRestored())
  {
    RESTORE(kgenericbacklight);
  }
  else
  {
    // no session.. just start up normally
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

    /// @todo do something with the command line args here

    mainWin = new kgenericbacklight();

    /* validate backlight interface found during class construction */
    if (mainWin->get_startupValid() == false) {
      app.quit();
      return 1;
    }

    app.setMainWidget (mainWin);
    if (haveicon) {
      mainWin->setIcon (icon);
    }
    mainWin->resize (mainWinSz);
    mainWin->show();

    args->clear();
  }

  // mainWin has WDestructiveClose flag by default, so it will delete itself.
  return app.exec();
}

