summaryrefslogtreecommitdiffstats
path: root/kcontrol/filetypes/typeslistitem.h
blob: 1946d9ab74ed2f822fa8f9a00a5a029be99f1e53 (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
/* This file is part of the KDE project
   Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
   Copyright (C) 2003 David Faure <faure@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef _TYPESLISTITEM_H
#define _TYPESLISTITEM_H

#include <tqlistview.h>

#include <kmimetype.h>
#include <kuserprofile.h>

class TypesListItem : public TQListViewItem
{
public:
  /**
   * Create a filetype group
   */
  TypesListItem(TQListView *parent, const TQString & major );

  /**
   * Create a filetype item inside a group
   */
  TypesListItem(TypesListItem *parent, KMimeType::Ptr mimetype, bool newItem=false);

  /**
   * Create a filetype item not inside a group (used by keditfiletype)
   */
  TypesListItem(TQListView *parent, KMimeType::Ptr mimetype);

  /**
   * Create a filetype item not inside a group (used by keditfiletype)
   * KDE4: merge with previous
   */
  TypesListItem(TQListView *parent, KMimeType::Ptr mimetype, bool newItem);

  ~TypesListItem();

  TQString name() const { return m_major + "/" + m_minor; }
  TQString majorType() const { return m_major; }
  TQString minorType() const { return m_minor; }
  void setMinor(TQString m) { m_minor = m; }
  TQString comment() const { return m_comment; }
  void setComment(TQString c) { m_comment = c; }
  /**
   * Returns true if "this" is a group
   */
  bool isMeta() const { return metaType; }
  /**
   * Returns true if the type is essential, i.e. can't be deleted
   * (see KMimeType::checkEssentialMimeTypes)
   */
  bool isEssential() const;
  TQString icon() const { return m_icon; }
  void setIcon(const TQString& i);
  TQStringList patterns() const { return m_patterns; }
  void setPatterns(const TQStringList &p) { m_patterns = p; }
  TQStringList appServices() const;
  void setAppServices(const TQStringList &dsl) { m_appServices = dsl; }
  TQStringList embedServices() const;
  void setEmbedServices(const TQStringList &dsl) { m_embedServices = dsl; }
  int autoEmbed() const { return m_autoEmbed; }
  void setAutoEmbed( int a ) { m_autoEmbed = a; }
  const KMimeType::Ptr& mimeType() const { return m_mimetype; }
  bool canUseGroupSetting() const;

  void getAskSave(bool &);
  void setAskSave(bool);

  // Whether the service s lists this mimetype explicitly
  KMimeType::Ptr findImplicitAssociation(const TQString &desktop);

  bool isMimeTypeDirty() const; // whether the mimetype .desktop file needs saving
  bool isDirty() const;
  void sync();
  void setup();
  void refresh(); // update m_mimetype from ksycoca when Apply is pressed

  static bool defaultEmbeddingSetting(  const TQString& major );
  static void reset();

private:
  void getServiceOffers( TQStringList & appServices, TQStringList & embedServices ) const;
  void saveServices( KConfig & profile, TQStringList services, const TQString & servicetype2 );
  void initMeta( const TQString & major );
  void init(KMimeType::Ptr mimetype);
  static int readAutoEmbed( KMimeType::Ptr mimetype );

  KMimeType::Ptr m_mimetype;
  unsigned int groupCount:16; // shared between saveServices and sync
  unsigned int m_autoEmbed:2; // 0 yes, 1 no, 2 use group setting
  unsigned int metaType:1;
  unsigned int m_bNewItem:1;
  unsigned int m_bFullInit:1;
  unsigned int m_askSave:2; // 0 yes, 1 no, 2 default
  TQString m_major, m_minor, m_comment, m_icon;
  TQStringList m_patterns;
  TQStringList m_appServices;
  TQStringList m_embedServices;
  static TQMap< TQString, TQStringList >* s_changedServices;
};

#endif