1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 *
10 * $Id: options.h 13381 2012-07-09 23:18:40Z jordan $
11 */
12
13#ifndef OPTIONS_DIALOG_H
14#define OPTIONS_DIALOG_H
15
16#include <iostream>
17
18#include <QDialog>
19#include <QEvent>
20#include <QString>
21#include <QDir>
22#include <QVector>
23#include <QMap>
24#include <QPushButton>
25#include <QString>
26#include <QStringList>
27#include <QCryptographicHash>
28#include <QFile>
29#include <QTimer>
30#include <QLineEdit>
31
32#include "add-data.h" // AddData
33#include "file-tree.h" // FileList
34
35class FileTreeView;
36class Prefs;
37class QCheckBox;
38class QComboBox;
39class Session;
40
41extern "C" { struct tr_benc; };
42
43class FileAdded: public QObject
44{
45        Q_OBJECT
46        const int64_t myTag;
47        QString myName;
48        QString myDelFile;
49
50    public:
51        FileAdded( int tag, const QString& name ): myTag(tag), myName(name) { }
52        ~FileAdded( ) { }
53        void setFileToDelete( const QString& file ) { myDelFile = file; }
54
55    public slots:
56        void executed( int64_t tag, const QString& result, struct tr_benc * arguments );
57};
58
59class Options: public QDialog
60{
61        Q_OBJECT
62
63    public:
64        Options( Session& session, const Prefs& prefs, const AddData& addme, QWidget * parent = 0 );
65        ~Options( );
66
67    private:
68        void reload( );
69        void clearInfo( );
70        void refreshFileButton( int width=-1 );
71        void refreshDestinationButton( int width=-1 );
72        void refreshButton( QPushButton *, const QString&, int width=-1 );
73
74    private:
75        Session& mySession;
76        AddData myAdd;
77        QDir myDestination;
78        bool myHaveInfo;
79        tr_info myInfo;
80        FileTreeView * myTree;
81        QCheckBox * myStartCheck;
82        QCheckBox * myTrashCheck;
83        QComboBox * myPriorityCombo;
84        QPushButton * myFileButton;
85        QPushButton * myDestinationButton;
86        QLineEdit * myDestinationEdit;
87        QPushButton * myVerifyButton;
88        QVector<int> myPriorities;
89        QVector<bool> myWanted;
90        FileList myFiles;
91
92    private slots:
93        void onAccepted( );
94        void onPriorityChanged( const QSet<int>& fileIndices, int );
95        void onWantedChanged( const QSet<int>& fileIndices, bool );
96        void onVerify( );
97        void onTimeout( );
98        void onFilenameClicked( );
99        void onDestinationClicked( );
100        void onFilesSelected( const QStringList& );
101        void onDestinationsSelected( const QStringList& );
102
103    private:
104        bool eventFilter( QObject *, QEvent * );
105
106    private:
107        QTimer myVerifyTimer;
108        char myVerifyBuf[2048*4];
109        QFile myVerifyFile;
110        uint64_t myVerifyFilePos;
111        int myVerifyFileIndex;
112        uint32_t myVerifyPieceIndex;
113        uint32_t myVerifyPiecePos;
114        void clearVerify( );
115        QVector<bool> myVerifyFlags;
116        QCryptographicHash myVerifyHash;
117        typedef QMap<uint32_t,int32_t> mybins_t;
118        mybins_t myVerifyBins;
119
120};
121
122#endif
123