]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmodel.cpp
2 * This file is part of the KDE project
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
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
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "dolphinmodel.h"
23 #include "dolphinsortfilterproxymodel.h"
25 #include "kcategorizedview.h"
27 #include <config-nepomuk.h>
29 #include <nepomuk/global.h>
30 #include <nepomuk/resource.h>
31 #include <nepomuk/tag.h>
34 #include <kdatetime.h>
35 #include <kdirmodel.h>
36 #include <kfileitem.h>
37 #include <kiconloader.h>
41 #include <kmimetype.h>
42 #include <kstandarddirs.h>
43 #include <kpixmapeffect.h>
46 #include <QSortFilterProxyModel>
51 DolphinModel :: DolphinModel ( QObject
* parent
)
56 DolphinModel ::~ DolphinModel ()
60 QVariant
DolphinModel :: data ( const QModelIndex
& index
, int role
) const
62 if ( role
== KCategorizedSortFilterProxyModel :: CategoryRole
)
71 const KDirModel
* dirModel
= qobject_cast
< const KDirModel
*>( index
. model ());
72 KFileItem item
= dirModel
-> itemForIndex ( index
);
74 switch ( index
. column ())
78 // KDirModel checks columns to know to which role are
80 QModelIndex theIndex
= index
. model ()-> index ( index
. row (),
84 if (! theIndex
. isValid ()) {
88 QVariant data
= theIndex
. model ()-> data ( theIndex
, Qt :: DisplayRole
);
89 if ( data
. toString (). size ())
91 if (! item
. isHidden () && data
. toString (). at ( 0 ). isLetter ())
92 retString
= data
. toString (). toUpper (). at ( 0 );
93 else if ( item
. isHidden () && data
. toString (). at ( 0 ) == '.' &&
94 data
. toString (). at ( 1 ). isLetter ())
95 retString
= data
. toString (). toUpper (). at ( 1 );
96 else if ( item
. isHidden () && data
. toString (). at ( 0 ) == '.' &&
97 ! data
. toString (). at ( 1 ). isLetter ())
98 retString
= i18nc ( "@title:group Name" , "Others" );
99 else if ( item
. isHidden () && data
. toString (). at ( 0 ) != '.' )
100 retString
= data
. toString (). toUpper (). at ( 0 );
101 else if ( item
. isHidden ())
102 retString
= data
. toString (). toUpper (). at ( 0 );
105 bool validCategory
= false ;
107 const QString
str ( data
. toString (). toUpper ());
108 const QChar
* currA
= str
. unicode ();
109 while (! currA
-> isNull () && ! validCategory
) {
110 if ( currA
-> isLetter ())
111 validCategory
= true ;
112 else if ( currA
-> isDigit ())
113 return i18nc ( "@title:group" , "Others" );
119 retString
= i18nc ( "@title:group Name" , "Others" );
127 case KDirModel :: Size
: {
128 const int fileSize
= ! item
. isNull () ? item
. size () : - 1 ;
129 if (! item
. isNull () && item
. isDir ()) {
130 retString
= i18nc ( "@title:group Size" , "Folders" );
131 } else if ( fileSize
< 5242880 ) {
132 retString
= i18nc ( "@title:group Size" , "Small" );
133 } else if ( fileSize
< 10485760 ) {
134 retString
= i18nc ( "@title:group Size" , "Medium" );
136 retString
= i18nc ( "@title:group Size" , "Big" );
141 case KDirModel :: ModifiedTime
:
143 KDateTime modifiedTime
;
144 modifiedTime
. setTime_t ( item
. time ( KIO :: UDSEntry :: UDS_MODIFICATION_TIME
));
145 modifiedTime
= modifiedTime
. toLocalZone ();
147 retString
= modifiedTime
. toString ( i18nc ( "Prints out the month and year: %B is full month name in current locale, and %Y is full year number" , " %B , %Y " ));
151 case KDirModel :: Permissions
:
157 QFileInfo
info ( item
. url (). pathOrUrl ());
159 if ( info
. permission ( QFile :: ReadUser
))
160 user
= i18n ( "Read, " );
162 if ( info
. permission ( QFile :: WriteUser
))
163 user
+= i18n ( "Write, " );
165 if ( info
. permission ( QFile :: ExeUser
))
166 user
+= i18n ( "Execute, " );
169 user
= i18n ( "Forbidden" );
171 user
= user
. mid ( 0 , user
. count () - 2 );
173 if ( info
. permission ( QFile :: ReadGroup
))
174 group
= i18n ( "Read, " );
176 if ( info
. permission ( QFile :: WriteGroup
))
177 group
+= i18n ( "Write, " );
179 if ( info
. permission ( QFile :: ExeGroup
))
180 group
+= i18n ( "Execute, " );
183 group
= i18n ( "Forbidden" );
185 group
= group
. mid ( 0 , group
. count () - 2 );
187 if ( info
. permission ( QFile :: ReadOther
))
188 others
= i18n ( "Read, " );
190 if ( info
. permission ( QFile :: WriteOther
))
191 others
+= i18n ( "Write, " );
193 if ( info
. permission ( QFile :: ExeOther
))
194 others
+= i18n ( "Execute, " );
196 if ( others
. isEmpty ())
197 others
= i18n ( "Forbidden" );
199 others
= others
. mid ( 0 , others
. count () - 2 );
201 retString
= i18nc ( "This shows files and folders permissions: user, group and others" , "(User: %1 ) (Group: %2 ) (Others: %3 )" , user
, group
, others
);
205 case KDirModel :: Owner
:
206 retString
= item
. user ();
209 case KDirModel :: Group
:
210 retString
= item
. group ();
213 case KDirModel :: Type
:
214 retString
= item
. mimeComment ();
218 case DolphinModel :: Rating
: {
219 const quint32 rating
= ratingForIndex ( index
);
221 retString
= QString :: number ( rating
);
225 case DolphinModel :: Tags
: {
226 retString
= tagsForIndex ( index
);
228 if ( retString
. isEmpty ())
229 retString
= i18nc ( "@title:group Tags" , "Not yet tagged" );
239 return KDirModel :: data ( index
, role
);
242 int DolphinModel :: columnCount ( const QModelIndex
& parent
) const
244 return KDirModel :: columnCount ( parent
) + ( ExtraColumnCount
- ColumnCount
);
247 quint32
DolphinModel :: ratingForIndex ( const QModelIndex
& index
)
252 const DolphinModel
* dolphinModel
= static_cast < const DolphinModel
*>( index
. model ());
253 KFileItem item
= dolphinModel
-> itemForIndex ( index
);
254 if (! item
. isNull ()) {
255 const Nepomuk :: Resource
resource ( item
. url (). url (), Nepomuk :: NFO :: File ());
256 rating
= resource
. rating ();
265 QString
DolphinModel :: tagsForIndex ( const QModelIndex
& index
)
270 const DolphinModel
* dolphinModel
= static_cast < const DolphinModel
*>( index
. model ());
271 KFileItem item
= dolphinModel
-> itemForIndex ( index
);
272 if (! item
. isNull ()) {
273 const Nepomuk :: Resource
resource ( item
. url (). url (), Nepomuk :: NFO :: File ());
274 const QList
< Nepomuk :: Tag
> tags
= resource
. tags ();
275 QStringList stringList
;
276 foreach ( const Nepomuk :: Tag
& tag
, tags
) {
277 stringList
. append ( tag
. label ());
281 foreach ( const QString
& str
, stringList
) {
286 if (! tagsString
. isEmpty ()) {
287 tagsString
. resize ( tagsString
. size () - 2 );