void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
{
    _other->setActive(isActive());
    _other->setApiVersion(apiVersion());
    _other->setComment(comment());
    _other->setCron(cron());
    _other->setInterval(interval());
    _other->setName(name());
    _other->setSocket(socket());
}
void AbstractExtItem::setCron(const QString &_cron)
{
    qCDebug(LOG_LIB) << "Cron string" << _cron;
    // deinit module first
    if (m_scheduler) {
        disconnect(m_scheduler, SIGNAL(activated()), this,
                   SIGNAL(requestDataUpdate()));
        delete m_scheduler;
    }

    m_cron = _cron;
    if (cron().isEmpty())
        return;

    // init scheduler
    m_scheduler = new QCronScheduler(this);
    m_scheduler->parse(cron());
    connect(m_scheduler, SIGNAL(activated()), this,
            SIGNAL(requestDataUpdate()));
}
void AbstractExtItem::readConfiguration()
{
    QSettings settings(m_fileName, QSettings::IniFormat);

    settings.beginGroup("Desktop Entry");
    setName(settings.value("Name", name()).toString());
    setComment(settings.value("Comment", comment()).toString());
    setApiVersion(settings.value("X-AW-ApiVersion", apiVersion()).toInt());
    setActive(settings.value("X-AW-Active", isActive()).toBool());
    setInterval(settings.value("X-AW-Interval", interval()).toInt());
    setNumber(settings.value("X-AW-Number", number()).toInt());
    setCron(settings.value("X-AW-Schedule", cron()).toString());
    setSocket(settings.value("X-AW-Socket", socket()).toString());
    settings.endGroup();
}
void AbstractExtItem::startTimer()
{
    if (!socket().isEmpty())
        // check if there is active socket setup
        return;
    else if (!cron().isEmpty())
        // check if there is active scheduler
        return;
    else if (m_times == 1)
        // check if it is time to update
        emit(requestDataUpdate());

    // update counter value
    if (m_times >= interval())
        m_times = 0;
    m_times++;
}
void AbstractExtItem::writeConfiguration() const
{
    QSettings settings(writtableConfig(), QSettings::IniFormat);
    qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();

    settings.beginGroup("Desktop Entry");
    settings.setValue("Encoding", "UTF-8");
    settings.setValue("Name", name());
    settings.setValue("Comment", comment());
    settings.setValue("X-AW-ApiVersion", apiVersion());
    settings.setValue("X-AW-Active", isActive());
    settings.setValue("X-AW-Interval", interval());
    settings.setValue("X-AW-Number", number());
    settings.setValue("X-AW-Schedule", cron());
    settings.setValue("X-AW-Socket", socket());
    settings.endGroup();

    settings.sync();
}
void start_server (void) {
  char buf[64];
  int i, prev_time = 0;

  init_epoll ();
  init_netbuffers ();

  if (!sfd) {
    sfd = server_socket (port, settings_addr, backlog, 0);
  }

  if (sfd < 0) {
    kprintf ("cannot open server socket at port %d: %m\n", port);
    exit (3);
  }

  vkprintf (1, "created listening socket at %s:%d, fd=%d\n", conv_addr (settings_addr.s_addr, buf), port, sfd);

  if (daemonize) {
    setsid ();
  }

  if (change_user (username) < 0) {
    kprintf ("fatal: cannot change user to %s\n", username ? username : "******");
    exit (1);
  }

  if (binlogname && !binlog_disabled) {
    assert (append_to_binlog (Binlog) == log_readto_pos);
  }

  init_listening_connection (sfd, &ct_rpc_server, &copyexec_result_rpc_server);

  sigset_t signal_set;
  sigemptyset (&signal_set);
  sigaddset (&signal_set, SIGINT);
  sigaddset (&signal_set, SIGTERM);
  sigaddset (&signal_set, SIGUSR1);
  if (daemonize) {
    sigaddset (&signal_set, SIGHUP);
  }
  struct sigaction act;
  act.sa_handler = copyexec_results_sig_handler;
  act.sa_mask = signal_set;
  act.sa_flags = 0;
  for (i = 1; i <= SIGRTMAX; i++) {
    if (sigismember (&signal_set, i)) {
      if (sigaction (i, &act, NULL) < 0) {
        kprintf ("sigaction (%d) failed. %m\n", i);
        exit (1);
      }
    }
  }

  for (i = 0; ; i++) {
    if (!(i & 255)) {
      vkprintf (1, "epoll_work(): %d out of %d connections, network buffers: %d used, %d out of %d allocated\n",
	       active_connections, maxconn, NB_used, NB_alloc, NB_max);
    }
    epoll_work (71);

    if (interrupted_by_term_signal ()) {
      break;
    }

    if (pending_signals & (1LL << SIGHUP)) {
      pending_signals_clear_bit (&signal_set, SIGHUP);
      kprintf ("got SIGHUP.\n");
      sync_binlog (2);
    }

    if (pending_signals & (1LL << SIGUSR1)) {
      pending_signals_clear_bit (&signal_set, SIGUSR1);
      kprintf ("got SIGUSR1, rotate logs.\n");
      reopen_logs ();
      sync_binlog (2);
    }

    if (now != prev_time) {
      prev_time = now;
      cron ();
    }
    if (quit_steps && !--quit_steps) break;
  }

  epoll_close (sfd);
  close (sfd);

  flush_binlog_last ();
  sync_binlog (2);
}