File: gpgfind.cpp

package info (click to toggle)
sim 0.9.5~svn20080806-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 18,108 kB
  • ctags: 11,570
  • sloc: cpp: 119,605; sh: 9,986; ansic: 3,312; perl: 2,752; lex: 1,533; makefile: 839; xml: 206; python: 56
file content (120 lines) | stat: -rw-r--r-- 3,454 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
                          gpgfind.cpp  -  description
                             -------------------
    begin                : Sun Mar 17 2002
    copyright            : (C) 2002 by Vladimir Shutoff
    email                : vovan@shutoff.ru
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <windows.h>

#include <qpixmap.h>
#include <qpushbutton.h>
#include <qdir.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qregexp.h>

#include "editfile.h"
#include "icons.h"
#include "misc.h"

#include "gpgfind.h"

using namespace SIM;

GpgFind::GpgFind(EditFile *edt)
        : GpgFindBase(NULL, NULL, false, WDestructiveClose)
{
    SET_WNDPROC("find")
    setIcon(Pict("find"));
    setButtonsPict(this);
    setCaption(caption());
    m_edit = edt;
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
    m_drives = *QDir::drives();
    m_drive  = m_drives.first();
    QTimer::singleShot(0, this, SLOT(next()));
}

GpgFind::~GpgFind()
{
    emit finished();
}

void GpgFind::next()
{
    if (!m_tree.empty()){
        QStringList &subDirs = m_tree.top();
        unsigned pos = m_pos.top();
        if (pos >= subDirs.count()){
            m_tree.pop();
            m_pos.pop();
            m_path = m_path.left(m_path.length() - 1);
            m_path = m_path.left(m_path.findRev('\\') + 1);
            QTimer::singleShot(0, this, SLOT(next()));
            return;
        }
        QString subDir = subDirs[pos++];
        m_pos.pop();
        m_pos.push(pos);
        if (!subDir.startsWith(".")){
            m_path += subDir;
            m_path += '\\';
            if (checkPath())
                return;
        }
        QTimer::singleShot(0, this, SLOT(next()));
        return;
    }
    if (m_drive == NULL){
        close();
        return;
    }
    m_path = m_drive->absFilePath();
    m_path = m_path.replace('/', '\\');
    if ((GetDriveTypeA(m_path.latin1()) == DRIVE_FIXED) && checkPath())
        return;
    m_drive = m_drives.next();
    QTimer::singleShot(0, this, SLOT(next()));
}

bool GpgFind::checkPath()
{
    QDir d(m_path);
    if (!d.exists())
        return false;
    QString p = m_path;
    if (p.length() > 40){
        p = "...";
        p += m_path.mid(m_path.length() - 38);
    }
    lblPath->setText(p);
    QFile f(m_path + "gpg.exe");
    if (f.exists()){
        m_edit->setText(m_path + "gpg.exe");
        QTimer::singleShot(0, this, SLOT(close()));
        return true;
    }
    QStringList subDirs = d.entryList(QDir::Dirs);
    if (!subDirs.isEmpty()){
        m_tree.push(subDirs);
        m_pos.push(0);
    }else{
        m_path = m_path.left(m_path.findRev('\\'));
    }
    return false;
}

#ifndef NO_MOC_INCLUDES
#include "gpgfind.moc"
#endif