1/*
2 kcodecaction.h
3
4 Copyright (c) 2003 Jason Keirstead <jason@keirstead.org>
5 Copyright (c) 2003-2006 Michel Hermier <michel.hermier@gmail.com>
6 Copyright (c) 2007 Nick Shaforostoff <shafff@ukr.net>
7
8 ********************************************************************
9 * *
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
14 * *
15 * This library is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU Lesser General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU Lesser General Public *
21 * License along with this library; if not, write to the *
22 * Free Software Foundation, Inc., 51 Franklin Street, *
23 * Fifth Floor, Boston, MA 02110-1301 USA *
24 * *
25 ********************************************************************
26*/
27#ifndef KCODECACTION_H
28#define KCODECACTION_H
29
30#include <kencodingdetector.h>
31#include <kselectaction.h>
32
33/**
34 * @short Action for selecting one of several QTextCodec.
35 *
36 * This action shows up a submenu with a list of the available codecs on the system.
37 */
38class KDEUI_EXPORT KCodecAction
39 : public KSelectAction
40{
41 Q_OBJECT
42
43 Q_PROPERTY(QString codecName READ currentCodecName WRITE setCurrentCodec)
44 Q_PROPERTY(int codecMib READ currentCodecMib)
45
46public:
47 explicit KCodecAction(QObject *parent,bool showAutoOptions=false);
48
49 KCodecAction(const QString &text, QObject *parent,bool showAutoOptions=false);
50
51 KCodecAction(const KIcon &icon, const QString &text, QObject *parent,bool showAutoOptions=false);
52
53 virtual ~KCodecAction();
54
55public:
56 int mibForName(const QString &codecName, bool *ok = 0) const;
57 QTextCodec *codecForMib(int mib) const;
58
59 QTextCodec *currentCodec() const;
60 bool setCurrentCodec(QTextCodec *codec);
61
62 QString currentCodecName() const;
63 bool setCurrentCodec(const QString &codecName);
64
65 int currentCodecMib() const;
66 bool setCurrentCodec(int mib);
67
68 /**
69 * Applicable only if showAutoOptions in c'tor was true
70 *
71 * @returns KEncodingDetector::None if specific encoding is selected, not autodetection, otherwise... you know it!
72 */
73 KEncodingDetector::AutoDetectScript currentAutoDetectScript() const;
74 /**
75 * Applicable only if showAutoOptions in c'tor was true
76 *
77 * KEncodingDetector::SemiautomaticDetection means 'Default' item
78 */
79 bool setCurrentAutoDetectScript(KEncodingDetector::AutoDetectScript);
80
81
82Q_SIGNALS:
83 /**
84 * Specific (proper) codec was selected
85 *
86 * Note that triggered(const QString&) is emitted too (as defined in KSelectAction)
87 */
88 void triggered(QTextCodec *codec);
89
90 /**
91 * Autodetection has been selected.
92 * emits KEncodingDetector::SemiautomaticDetection if Default was selected.
93 *
94 * Applicable only if showAutoOptions in c'tor was true
95 */
96 void triggered(KEncodingDetector::AutoDetectScript);
97
98 /**
99 * If showAutoOptions==true, then better handle triggered(KEncodingDetector::AutoDetectScript) signal
100 */
101 void defaultItemTriggered();
102
103
104protected Q_SLOTS:
105 virtual void actionTriggered(QAction*);
106
107protected:
108 using KSelectAction::triggered;
109
110private:
111 class Private;
112 Private* const d;
113
114 Q_PRIVATE_SLOT( d, void _k_subActionTriggered(QAction*) )
115};
116
117#endif
118