#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QtGui>
#include <QDomDocument>
#include <QSettings>
#include <QMainWindow>
#include <qnetworksession.h>
#include <QNetworkSession>

#include "postSearchListModel.h"
#include "postSearchListDelegate.h"
#include "blogSearchListDelegate.h"
#include "blogSearchListModel.h"
#include "districtareaListdelegate.h"
#include "districtareaListmodel.h"
#include "tradeListDelegate.h"
#include "tradelistmodel.h"
#include "floorplanlistdelegate.h"
#include "floorplanlistmodel.h"

#include <e32base.h>
#include <Etel3rdParty.h>
#include <QTimer>

QTM_USE_NAMESPACE

namespace Ui {
    class MainWindow;
}
class postSearchListModel;

class MainWindow : public QMainWindow,CActive
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void RunL();
    TInt RunError(TInt aError);
    void DoCancel();

private:
    Ui::MainWindow *ui;
    void makeCall(QString text);
    CTelephony*                   iTelephony;
    CTelephony::TCallId           iCallId;
    CTelephony::TCallParamsV1     iCallParams;
    CTelephony::TCallParamsV1Pckg iCallParamsPckg;
    QPixmap p;
    QPixmap p2[150];
    QString contact;
    QNetworkAccessManager* topEstatesMan;
    QNetworkAccessManager* AreaMan;
    QString type;
    QString code;
    QSettings settings;
    int postOrBlog;
    QMessageBox msgBox2;
    QPushButton *connectButton;
    QMessageBox msgBox3;
    QMessageBox msgBox4;
    QPushButton *connectButton2;
    QPushButton *connectButton3;

    QMessageBox recordMsgBox;
    QPushButton *checkButton;
    QPushButton *deleteButton;

    QMessageBox record360MsgBox;
    QPushButton *check360Button;
    QPushButton *delete360Button;

    QMessageBox callMsgBox;
    QPushButton *callButton;





    bool isDetail;

    //searchBox
    QNetworkAccessManager * searchBoxManager;
    QStringList searchBoxName;
    QStringList searchBoxNameEn;
    QStringList searchBoxAddress;
    QStringList searchBoxType;
    QStringList searchBoxCode;

    //downloadStuff
    QNetworkAccessManager *nam;
    QNetworkAccessManager *networkManager;
    QNetworkSession* session;
    QNetworkReply *r;

    //NewProp
    QStringList newPropImageName;
    QStringList newPropImageThumb;
    QStringList newPropFloorPlanName;
    QStringList newPropFloorPlanThumb;
    QStringList newPropBranchName;
    QStringList newPropBranchAddress;
    QStringList newPropVideoName;
    QStringList newPropVideoThumb;
    QStringList newPropVideoUrl;
    QStringList newPropEmail;
    QStringList emptyList;
    QNetworkAccessManager* newPropMan;
    QNetworkAccessManager* newPropImageMan;
    QNetworkAccessManager* newPropDetailMan;
    QNetworkAccessManager* newPropDetailImageMan;
    QNetworkAccessManager* newPropFloorPlanImageMan;
    QNetworkAccessManager* newPropListImageMan;
    QNetworkAccessManager* newPropVideoImageMan;
    QNetworkAccessManager* newPropPreviewImageMan;
    QNetworkAccessManager* newPropPreviewFloorPlanImageMan;
    QPixmap newPropFloorPlanImage[150];
    QPixmap newPropListImage[150];
    QPixmap newPropVideoImage[10];
    int imageCount;
    int videoCount;


    //GeoLocationPost
    QNetworkAccessManager* geoPostMan;
    QNetworkAccessManager* geoPostImageMan;
    bool geoSell;

    //GeoLocation360
    QNetworkAccessManager* geo360Man;
    QNetworkAccessManager* geo360ImageMan;


    //Record
    QString record360;
    QString recordPost;
    QString recordRent;
    QNetworkAccessManager* record360Man;
    QNetworkAccessManager* record360ImageMan;
    QNetworkAccessManager* recordPostMan;
    QNetworkAccessManager* recordPostImageMan;
    int recordPostCount;
    bool isRecord;


    //Recent Read
    QString recentReadCode1;
    QString recentReadCode2;
    QString recentReadCode3;
    QNetworkAccessManager* recentReadMan;
    QNetworkAccessManager* recentReadImage1Man;
    QNetworkAccessManager* recentReadImage2Man;
    QNetworkAccessManager* recentReadImage3Man;
    void getRecentRead();
    void detail360Handler2(QString t,QString c);

    //Facility
    QStringList faciltyName;
    QStringList faciltyThumb;
    QStringList faciltyLink;
    QPixmap faciltyImage[150];

    //FloorPlan
    QNetworkAccessManager* floorPlanMan;
    QNetworkAccessManager* floorPlanImageMan;
    QStringList floorPlanName;
    QStringList floorPlanThumb;
    QStringList floorPlanLink;
    QPixmap floorPlanImage[150];
    int floorCount;
    QString floorPlanType;
    QString floorPlanCode;

    //360MainPage
    QNetworkAccessManager* topThreeMan;
    QNetworkAccessManager* district360MoreMan;
    QNetworkAccessManager* district360MoreImageMan;

    //360Detail
    QNetworkAccessManager* detail360Man1;
    QNetworkAccessManager* detail360Man2;
    QNetworkAccessManager* detail360Man3;
    QNetworkAccessManager* detail360Man4;
    QNetworkAccessManager* detail360Man5;
    QNetworkAccessManager* detail360Man6;
    QNetworkAccessManager* detail360Man7;
    QNetworkAccessManager* detail360ChartMan;
    QNetworkAccessManager* previewEstateMan;
    QNetworkAccessManager* previewFacilityMan;
    QNetworkAccessManager* facilityImageMan;
    QStringList address_s;
    QStringList date_s;
    QStringList price_s;
    QStringList size_s;
    QStringList pps_s;
    QStringList type_s;
    QStringList address_r;
    QStringList date_r;
    QStringList price_r;
    QStringList size_r;
    QStringList pps_r;
    QStringList type_r;
    void detail360Handler(int index);
    int estateNumber;
    int facilityNumber;
    int sellSii;
    int rentSii;
    int _index;

    //DistrictSearch
    QNetworkAccessManager* districtSearchMan;
    QNetworkAccessManager* districtSearchImageMan;
    QString districtLink;
    QNetworkAccessManager* districtAreaMan;
    QNetworkAccessManager* districtAreaImageMan;
    QStringList districtAreaName;
    QStringList districtAreaNameEn;
    QStringList districtAreaThumb;
    QStringList districtAreaCode;
    QStringList districtAreaType;
    QStringList districtAreaPrice;
    QStringList districtAreaPPS;
    QStringList districtAreaPercent;
    QPixmap districtThumb[150];
    int districtCount;


    //Preview
    QNetworkAccessManager* previewImageMan;
    int imageNumber;
    int districtSii;

    //PostSearch
    bool postBuy;
    int areaType;
    QString postCode;
    QString postType;
    QString pt;
    QString postPrice;
    QString postSize;
    QString roomNumber;
    QString keyWord;
    QString refNo;
    QPixmap postThumb[150];
    int postSii;
    int pageNumber;
    QNetworkAccessManager* postSearchMan;
    QNetworkAccessManager* postImageMan;
    QNetworkAccessManager* postDetailMan;
    QNetworkAccessManager* postDetailImageMan;
    QNetworkAccessManager* postDetailAgentImageMan;
    int postCount;
    QStringList name;
    QStringList area;
    QStringList price;
    QStringList room;
    QStringList thumb;
    QStringList pps;
    QStringList size;
    QStringList suite;
    QStringList refNoList;
    QPixmap agentImage;
    QNetworkAccessManager* recentTradeMan;

    //blogSearch
    QString blogCode;
    QString blogType;
    QString blogLicense;
    QString blogName;
    QNetworkAccessManager* blogSearchMan;
    QNetworkAccessManager* blogImageMan;
    QNetworkAccessManager* blogDetailMan;
    QNetworkAccessManager* blogDetailImageMan;
    int blogCount;
    int blogSii;
    bool isSell;
    QStringList agentName;
    QStringList agentNameEn;
    QStringList agentAddress;
    QStringList agentCount;
    QStringList agentThumb;
    QStringList license;
    QPixmap blogThumb[150];




    void getTopEstates();
    void ChecktopEstatesWordLength(QPushButton* label,QString string);

    QStringList  m_slData;



    //XML
    QDomDocument areaXml;
    QDomDocument postXml;
    QDomDocument blogXml;
    QDomDocument postDetailXml;
    QDomDocument districtXml;
    QDomDocument districtListXml;
    QDomDocument districtAreaXml;
    QDomDocument recentTradeXml;
    QDomDocument topThreeXml;
    QDomDocument previewEstateXml;
    QDomDocument previewFacilityXml;
    QDomDocument recentReadXml;
    QDomDocument newPropXml;
    QDomDocument searchBoxXml;

public slots:
    void downloadingIssueFinished();

private slots:
    void quitApp();

    void splashTimeout();

    void calltoAgent();
    void calltoAgent2();
    void calltoAgent3();
    void calltoBranch();

    void mainBack();


    //downloadStuff
    void finished(QNetworkReply *reply);
    void DoHttpGet();

    //searchBox
    void searchBox();
    void searchBoxResult(QNetworkReply *reply);
    void searchBoxClicked(QModelIndex index);

    //TabControl
    void changeTab1_1();
    void changeTab1_2();
    void changeTab1_3();
    void changeTab1_4();
    void changeTab2_1();
    void changeTab2_2();
    void changeTab2_3();
    void changeTab2_4();

    //RequestForm
    void resetForm();
    void submitForm();

    //NewProp
    void newPropClicked(QModelIndex index);
    void newPropChangeToHK();
    void newPropChangeToKL();
    void newPropChangeToNT();
    void newPropChangeToHOT();
    void newPropResult(QNetworkReply* reply);
    void newPropImageDownloaded(QNetworkReply* reply);
    void newPropDetailResult(QNetworkReply* reply);
    void newPropDetailImageDownloaded(QNetworkReply* reply);
    void newPropListImageDownloaded(QNetworkReply* reply);
    void newPropFloorPlanImageDownloaded(QNetworkReply* reply);
    void newPropVideoImageDownloaded(QNetworkReply* reply);
    void newPropImageClicked(QModelIndex index);
    void newPropVideoClicked(QModelIndex index);
    void newPropPreviewImageDownloaded(QNetworkReply* reply);
    void newPropFloorPlanClicked(QModelIndex index);
    void newPropPreviewFloorPlanImageDownloaded(QNetworkReply* reply);
    void newPropContactClicked(QModelIndex index);
    void newPropImageDownload();
    void newPropFloorPlanDownload();


    //GeoLocationPost
    void geoLocationPostClicked(QModelIndex index);
    void geoLocationPostResult(QNetworkReply* reply);
    void geoLocationPostImageDownloaded(QNetworkReply* reply);
    void geolocationchangetoRent();
    void geolocationchangetoSell();

    //GeoLocation360
    void geoLocation360Clicked(QModelIndex index);
    void geoLocation360Result(QNetworkReply* reply);
    void geoLocation360ImageDownloaded(QNetworkReply* reply);
    void geolocationchangeto500m();
    void geolocationchangeto1000m();
    void geolocationchangeto1500m();

    //Record
    void record360Save();
    void recordPostSave();
    void record360View();
    void recordPostView();
    void record360ListResult(QNetworkReply* reply);
    void record360ListImageDownladed(QNetworkReply* reply);
    void record360ListClicked(QModelIndex index);
    void recordPostListResult(QNetworkReply* reply);
    void recordPostListImageDownladed(QNetworkReply* reply);
    void recordPostListClicked(QModelIndex index);
    void recordPostClean();
    void record360Clean();
    void recordChangetoRent();
    void recordChangetoSell();
    void recordCheck();
    void recordDelete();
    void record360Check();
    void record360Delete();


    //Recent Read
    void recentReadResult(QNetworkReply* reply);
    void recentReadImageDownloaded1(QNetworkReply* reply);
    void recentReadImageDownloaded2(QNetworkReply* reply);
    void recentReadImageDownloaded3(QNetworkReply* reply);
    void recentReadRecord1();
    void recentReadRecord2();
    void recentReadRecord3();

    //FloorPlan
    void floorPlanSearch();
    void floorPlanResult(QNetworkReply* reply);
    void floorPlanImageDownloaded(QNetworkReply* reply);
    void floorPlanClicked(QModelIndex index);

    //360Detail
    void detail360Result1(QNetworkReply* reply);
    void detail360Result2(QNetworkReply* reply);
    void detail360Result3(QNetworkReply* reply);
    void detail360Result4(QNetworkReply* reply);
    void detail360Result5(QNetworkReply* reply);
    void detail360previewEstate(QNetworkReply* reply);
    void detail360previewFacility(QNetworkReply* reply);
    void previewEstateDownloaded(QNetworkReply* reply);
    void previewFacilityDownloaded(QNetworkReply* reply);
    void detail360ChartDownloaded(QNetworkReply* reply);
    void tradeRentListUpdated();
    void tradeSellListUpdated();
    void nextEstateImage();
    void previousEstateImage();
    void nextFacilityImage();
    void previousFacilityImage();
    void downloadEstate();
    void downloadFacility();
    void facilityClicked(QModelIndex index);
    void facilityImageDownloaded(QNetworkReply* reply);

    //360MainPage
    void topThreeEstate();
    void topThreeEstateFinished(QNetworkReply* reply);
    void district360MoreResult(QNetworkReply* reply);
    void district360MoreImageDownloaded(QNetworkReply* reply);
    void distict360MoreClicked(QModelIndex index);
    void hk1Btn360Clicked();
    void hk2Btn360Clicked();
    void hk3Btn360Clicked();
    void hk4Btn360Clicked();
    void kl1Btn360Clicked();
    void kl2Btn360Clicked();
    void kl3Btn360Clicked();
    void kl4Btn360Clicked();
    void nte1Btn360Clicked();
    void nte2Btn360Clicked();
    void nte3Btn360Clicked();
    void nte4Btn360Clicked();
    void ntw1Btn360Clicked();
    void ntw2Btn360Clicked();
    void ntw3Btn360Clicked();
    void ntw4Btn360Clicked();


    //DistrictSearch
    void hk1BtnClicked();
    void hk2BtnClicked();
    void hk3BtnClicked();
    void hk4BtnClicked();
    void kl1BtnClicked();
    void kl2BtnClicked();
    void kl3BtnClicked();
    void kl4BtnClicked();
    void nte1BtnClicked();
    void nte2BtnClicked();
    void nte3BtnClicked();
    void nte4BtnClicked();
    void ntw1BtnClicked();
    void ntw2BtnClicked();
    void ntw3BtnClicked();
    void ntw4BtnClicked();
    void districtSearchResult(QNetworkReply* reply);
    void districtImageDownloaded(QNetworkReply* reply);
    void districtAreaResult(QNetworkReply* reply);
    void districtAreaImageDownloaded(QNetworkReply* reply);
    void districtListChangeToSell();
    void districtListChangeToRent();
    void districtListUpdated();
    void districtListClicked(QModelIndex index);
    void districtAreaListClicked(QModelIndex index);


    //Preview
    void previewImageDownload();
    void previreImageDownloadFinished(QNetworkReply* reply);
    void nextImage();
    void previousImage();

    //PostSearch
    void postSell();
    void postRent();
    void displayPrice(int x);
    void displayArea(int x);
    void resetPostSearch();
    void postSearch();
    void postListClicked(QModelIndex index);
    void postListUpdated();
    void postImageDownloaded(QNetworkReply* reply);
    void postDetailFinished(QNetworkReply* reply);
    void postDetailImageFinished(QNetworkReply* reply);
    void postDetailAgentImageFinished(QNetworkReply* reply);
    void postSearchResult(QNetworkReply* reply);
    void postDetailPromotion();
    void recentTradeResult(QNetworkReply* reply);
    void postDetailpreviousPage();
    void trade1Click();
    void trade2Click();
    void trade3Click();


    //BlogSearch
    void resetBlogSearch();
    void blogSearch();
    void blogSearchResult(QNetworkReply* reply);
    void blogImageDownloaded(QNetworkReply* reply);
    void blogListClicked(QModelIndex index);
    void blogListUpdated();
    void blogDetailListUpdated();
    void blogDetailResult(QNetworkReply* reply);
    void blogDetailImageDownloaded(QNetworkReply* reply);
    void blogDetailClicked(QModelIndex index);
    void blogDetailChangeToSell();
    void blogDetailChangeToRent();



    //pageControl
    void pageConditionSearch();
    void pageWeb();
    void pageArea();
    void pageBlog();
    void pageTNC();
    void pageDetail1();
    void pageDetail2();
    void pagePreview();
    void pageChartDetail();
    void page360Detail();
    void pageSell();
    void pageRent();
    void pageFlatDetail();
    void pageFacility();
    void pageEstatePreview();
    void pageFacilityPreview();
    void pageFloorPlanList();
    void pageGeoLocationPost();
    void pageGeoLocation360();
    void pageNewPropDetail();
    void pageNewPropImage();
    void pageNewPropFloorPlan();
    void pageNewPropVideo();
    void pageNewPropContact();
    void pageRequestForm();
    void pageFaciltyList();
    void pageCharacter();


    //LoadXML
    void topEstatesFinished(QNetworkReply* reply);
    void areaFinished(QNetworkReply* reply);


    //areaPage
    void changeToHKList();
    void changeToKLList();
    void changeToNTEList();
    void changeToNTWList();
    void currentClicked(QModelIndex index);
};

#endif // MAINWINDOW_H
