summaryrefslogtreecommitdiffstats
path: root/src/common/gui/purl_gui.h
blob: 7a97c7c959a5936725ff1c22a31e38a5ed30a04c (plain)
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
121
122
123
124
125
/***************************************************************************
 *   Copyright (C) 2006-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/
#ifndef PURL_GUI_H
#define PURL_GUI_H

#include <tqvgroupbox.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <kurllabel.h>

#include "common/global/purl.h"
#include "editlistbox.h"

namespace PURL
{
//-----------------------------------------------------------------------------
extern bool hasMimetype(FileType type);
extern TQPixmap icon(FileType type);
extern Directory getExistingDirectory(const TQString &startDir, TQWidget *widget, const TQString &caption);
extern Url getOpenUrl(const TQString &startDir, const TQString &filter, TQWidget *widget,
                      const TQString &caption);
extern UrlList getOpenUrls(const TQString &startDir, const TQString &filter, TQWidget *widget,
                          const TQString &caption);
enum SaveAction { NoSaveAction, AskOverwrite, CancelIfExists };
extern Url getSaveUrl(const TQString &startDir, const TQString &filter, TQWidget *widget,
                      const TQString &caption, SaveAction action);

//-----------------------------------------------------------------------------
class Label : public KURLLabel
{
TQ_OBJECT
  
public:
  Label(const TQString &url, const TQString &text, TQWidget *parent = 0, const char *name = 0);

private slots:
  void urlClickedSlot();
};

//-----------------------------------------------------------------------------
class BaseWidget : public TQWidget
{
TQ_OBJECT
  
public:
  BaseWidget(TQWidget *parent = 0, const char *name = 0);
  BaseWidget(const TQString &defaultDir, TQWidget *parent = 0, const char *name = 0);
  KLineEdit *lineEdit() { return _edit; }

signals:
  void changed();

protected slots:
  virtual void buttonClicked() = 0;

protected:
  TQString    _defaultDir;
  KLineEdit *_edit;

  void init();
};

//-----------------------------------------------------------------------------
class DirectoryWidget : public BaseWidget
{
TQ_OBJECT
  
public:
  DirectoryWidget(TQWidget *parent = 0, const char *name = 0) : BaseWidget(parent, name) {}
  DirectoryWidget(const TQString &defaultDir, TQWidget *parent = 0, const char *name = 0) : BaseWidget(defaultDir, parent, name) {}
  void setDirectory(const Directory &dir) { _edit->setText(dir.path()); }
  Directory directory() const { return _edit->text(); }

protected slots:
  virtual void buttonClicked();
};

//-----------------------------------------------------------------------------
class DirectoriesWidget : public TQVGroupBox
{
TQ_OBJECT
  
public:
  DirectoriesWidget(const TQString &title, TQWidget *parent = 0, const char *name = 0);
  DirectoriesWidget(const TQString &title, const TQString &defaultDir, TQWidget *parent = 0, const char *name = 0);
  void setDirectories(const TQStringList &dirs) { _editListBox->setTexts(dirs); }
  TQStringList directories() const { return _editListBox->texts(); }

signals:
  void changed();

private:
  EditListBox *_editListBox;
  void init(const TQString &defaultDir);
};

//-----------------------------------------------------------------------------
class UrlWidget : public BaseWidget
{
TQ_OBJECT
  
public:
  UrlWidget(const TQString &filter, TQWidget *parent = 0, const char *name = 0)
    : BaseWidget(parent, name), _filter(filter) {}
  UrlWidget(const TQString &defaultDir, const TQString &filter, TQWidget *parent = 0, const char *name = 0)
    : BaseWidget(defaultDir, parent, name), _filter(filter) {}
  Url url() const { return PURL::Url::fromPathOrUrl(_edit->text()); }
  void setUrl(const Url &url) { _edit->setText(url.filepath()); }

protected slots:
  virtual void buttonClicked();

private:
  TQString _filter;
};

} // namespace

#endif