summaryrefslogtreecommitdiffstats
path: root/knode/utilities.h
blob: 989388759f4187e5836b3528f701c8aae286212c (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
    KNode, the KDE newsreader
    Copyright (c) 1999-2005 the KNode authors.
    See file AUTHORS for details

    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.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/

#ifndef UTILITIES_H
#define UTILITIES_H

#include <kurl.h>

#include <tqfile.h>

#include <tqglobal.h>
#include <tqptrvector.h>
#include <tqptrlist.h>

class TQWidget;
class TQString;
class TQChar;
class TQStringList;
class TQSize;

class KTempFile;


//*****************************************************************************
// utility classes
//*****************************************************************************

class KNFile : public TQFile {

  public:
    KNFile(const TQString& fname=TQString());
    ~KNFile();
    const TQCString& readLine();
    const TQCString& readLineWnewLine();
    /** searches for the string from the current file position
	returns -1 when the string wasn't found. */
    int findString(const char *s);

   protected:
    bool increaseBuffer();

    TQCString buffer;
    char *dataPtr;
    int filePos, readBytes;
};


//========================================================================================


class KNSaveHelper {

public:

  KNSaveHelper(TQString saveName, TQWidget *parent);
  ~KNSaveHelper();

  /** returns a file open for writing */
  TQFile* getFile(const TQString &dialogTitle);

private:

  TQWidget *p_arent;
  TQString s_aveName;
  KURL url;
  TQFile* file;
  KTempFile* tmpFile;
  static TQString lastPath;

};


//========================================================================================


class KNLoadHelper {

public:

  KNLoadHelper(TQWidget *parent);
  ~KNLoadHelper();

  /** opens a file dialog and returns a file open for reading */
  KNFile* getFile( const TQString &dialogTitle );
  /** tries to access the file specified by the url and returns
      a file open for reading */
  KNFile* setURL(KURL url);
  /** returns the file after getFile(TQString) of setURL(url) was called */
  KNFile* getFile()const { return f_ile; };
  KURL getURL() const    { return u_rl; };

private:

  TQWidget *p_arent;
  KURL u_rl;
  KNFile *f_ile;
  TQString t_empName;
  static TQString l_astPath;

};


//========================================================================================


class KNHelper {

public:

  /** list selection dialog, used instead of a popup menu
      when a select action is called via the keyboard.
      returns -1 when the user canceled the dialog. */
  static int selectDialog(TQWidget *parent, const TQString &caption, const TQStringList &options, int initialValue);

  static void saveWindowSize(const TQString &name, const TQSize &s);
  static void restoreWindowSize(const TQString &name, TQWidget *d, const TQSize &defaultSize);

  static const TQString encryptStr(const TQString& aStr);
  static const TQString decryptStr(const TQString& aStr);
  static TQString rot13(const TQString &s);

  /** used for rewarping a text when replying to a message or inserting a file into a box */
  static TQString rewrapStringList(TQStringList text, int wrapAt, TQChar quoteChar, bool stopAtSig, bool alwaysSpace);

  /** use this for all internal files */
  static void displayInternalFileError(TQWidget *w=0);
  /** use this for all external files */
  static void displayExternalFileError(TQWidget *w=0);
  /** use this for remote files */
  static void displayRemoteFileError(TQWidget *w=0);
  /** use this for error on temporary files */
  static void displayTempFileError(TQWidget *w=0);

};

#endif