1 | /* |
2 | Copyright (c) 2005 Tom Albers <tomalbers@kde.nl> |
3 | Copyright (c) 1997-1999 Stefan Taferner <taferner@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or modify it |
6 | under the terms of the GNU Library General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or (at your |
8 | option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
13 | License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to the |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KPIMUTILS_KFILEIO_H |
22 | #define KPIMUTILS_KFILEIO_H |
23 | |
24 | #include "kpimutils_export.h" |
25 | |
26 | class QByteArray; |
27 | class QString; |
28 | class QWidget; |
29 | |
30 | namespace KPIMUtils { |
31 | |
32 | /** |
33 | Loads the file with the given filename. Optionally, you can force the data |
34 | to end with a newline character. Moreover, you can suppress warnings. |
35 | |
36 | @param fileName Name of the file that should be loaded. |
37 | @param ensureNewline If true, then the data will always have a trailing |
38 | newline. Defaults to true. |
39 | @param withDialogs If false, then no warning dialogs are shown in case of |
40 | problems. Defaults to true. |
41 | |
42 | @return The contents of the file or an empty QByteArray if loading failed. |
43 | */ |
44 | KPIMUTILS_EXPORT QByteArray kFileToByteArray( const QString & fileName, |
45 | bool ensureNewline = true, |
46 | bool withDialogs = true ); |
47 | |
48 | /** |
49 | Writes the contents of @p buffer to the file with the given filename. |
50 | |
51 | @param buffer The data you want to write to the file. |
52 | @param fileName The output file name |
53 | @param askIfExists If true, then you will be asked before an existing file |
54 | is overwritten. If false, then an existing file is |
55 | overwritten without warning. |
56 | @param createBackup If true, then a backup of existing files will be |
57 | created. Otherwise, no backup will be made. |
58 | @param withDialogs If true, then you will be warned in case of problems. |
59 | Otherwise, no warnings will be issued. |
60 | |
61 | @return True if writing the data to the file succeeded. |
62 | @return False if writing the data to the file failed. |
63 | */ |
64 | KPIMUTILS_EXPORT bool kByteArrayToFile( const QByteArray & buffer, |
65 | const QString & fileName, |
66 | bool askIfExists = false, |
67 | bool createBackup = true, |
68 | bool withDialogs = true ); |
69 | |
70 | /** |
71 | Checks and corrects the permissions of a file or folder, and if requested |
72 | all files and folders below. It gives back a list of files which do not |
73 | have the right permissions. This list can be used to show to the user. |
74 | |
75 | @param toCheck The file or folder of which the permissions should |
76 | be checked. |
77 | @param recursive Set to true, it will check the contents of a folder |
78 | for the permissions recursively. If false only |
79 | toCheck will be checked. |
80 | @param wantItReadable Set to true, it will check for read permissions. |
81 | If the read permissions are not available, there will |
82 | be a attempt to correct this. |
83 | @param wantItWritable Set to true, it will check for write permissions. |
84 | If the write permissions are not available, there |
85 | will be a attempt to correct this. |
86 | @return It will return a string with all files and folders which do not |
87 | have the right permissions. If empty, then all permissions are ok. |
88 | */ |
89 | KPIMUTILS_EXPORT QString checkAndCorrectPermissionsIfPossible( const QString &toCheck, |
90 | const bool recursive, |
91 | const bool wantItReadable, |
92 | const bool wantItWritable ); |
93 | |
94 | /** |
95 | Checks and corrects the permissions of a file or folder, and if requested all |
96 | files and folders below. If the permissions are not ok, it tries to correct |
97 | them. If that fails then a warning with detailled information is given. |
98 | |
99 | @param parent If parent is 0, then the message box becomes an |
100 | application-global modal dialog box. If parent |
101 | is a widget, the message box becomes modal |
102 | relative to parent. |
103 | @param toCheck The file or folder of which the permissions should |
104 | be checked. |
105 | @param recursive Set to true, it will check the contents of a folder |
106 | for the permissions recursively. If false only |
107 | toCheck will be checked. |
108 | @param wantItReadable Set to true, it will check for read permissions. |
109 | If the read permissions are not available, there will |
110 | be a attempt to correct this. |
111 | @param wantItWritable Set to true, it will check for write permissions. |
112 | If the write permissions are not available, there |
113 | will be a attempt to correct this. |
114 | @return It will return true if all permissions in the end are ok. If false |
115 | then the permissions are not ok and it was not possible to correct |
116 | all errors. |
117 | |
118 | @deprecated unused, scheduled for removal in KF5. |
119 | */ |
120 | KPIMUTILS_DEPRECATED_EXPORT bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( QWidget *parent, |
121 | const QString &toCheck, |
122 | const bool recursive, |
123 | const bool wantItReadable, |
124 | const bool wantItWritable ); |
125 | |
126 | /** |
127 | * Removed a directory on the local filesystem whether it is empty or not. All |
128 | * contents are irredeemably lost. |
129 | * |
130 | * @param path An absolute or relative path to the directory to be |
131 | * removed. |
132 | * |
133 | * @return Success or failure. |
134 | */ |
135 | KPIMUTILS_EXPORT bool removeDirAndContentsRecursively( const QString & path ); |
136 | |
137 | } |
138 | |
139 | #endif |
140 | |