#ifndef AUCTION_H
#define AUCTION_H

#include <QTreeWidgetItem>
#include <QUrl>
#include <QString>
#include <QTimer>
#include <QDesktopServices>
#include <kapplication.h>
#include <kfiledialog.h>
#include <kglobal.h>
#include <QListIterator>
#include <QDebug>
#include <QDateTime>
#include <QPixmap>
#include <kdatetime.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstatusnotifieritem.h>
#include <knotification.h>
#include <limits.h>

class Auction : public QObject, public QTreeWidgetItem
{
  Q_OBJECT
  
  public:
    Auction(QWidget* parent, const int timeOffseteBayToLocal);
    ~Auction();
    void setTitle(const QString &title);
    QString title(void) const;
    void setUrl(const QUrl &url);
    QUrl url() const;

    void setItemId(const QString &itemId);
    QString itemId(void) const;
    
    void setCurrency(const QString &currency);
    void setBidCount(const int bidCount);
    void setPriceCurrent(const QString &priceCurrent);
    void setPriceBuyNow(const QString &priceBuyNow);
    void setEnd(const QDateTime &end);

    void setPixmap(const QPixmap &pixmap);
    QPixmap pixmap(void) const;
    
    void update(const bool translateEndTimes);

  private:
    QString formatDuration(int secondsToEnd) const;
    int getTimeToEnd(bool includeOffset=true) const;

    QWidget* m_parent;
    QString m_title, m_currency, m_priceCurrent, m_priceBuyNow, m_itemId;
    QUrl m_url;
    int m_bidCount, m_timeOffseteBayToLocal;
    QDateTime m_end;
    QPixmap m_pixmap;

    // The timer for the notification
    QTimer* m_notificationTimer;

    bool m_openBrowserOnNextAlarm;
    
    // If there has already been a notification for this item at n minutes before end,
    // remove that Notification before displaying the next at less than n minutes before end.
    KNotification* m_previousNotification;

  private slots:
    void slotSetNextAlarm();
    void slotAlarm();
    void slotNotificationActivated(unsigned int);
    void slotNotificationClosed();

  signals:
    void openBrowserForAlarm(QTreeWidgetItem*);
};

#endif
