~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to pimcommon/aclutils.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
 
3
 * Copyright (c) 2010 Tobias Koenig <tokoe@kdab.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program 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
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "aclutils_p.h"
 
21
 
 
22
#include <KLocale>
 
23
 
 
24
using namespace PimCommon;
 
25
 
 
26
static const struct {
 
27
  KIMAP::Acl::Rights permissions;
 
28
  const char *userString;
 
29
} standardPermissions[] = {
 
30
  { KIMAP::Acl::None,
 
31
    I18N_NOOP2( "Permissions", "None" ) },
 
32
 
 
33
  { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen,
 
34
    I18N_NOOP2( "Permissions", "Read" ) },
 
35
 
 
36
  { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen |
 
37
    KIMAP::Acl::Insert | KIMAP::Acl::Post,
 
38
    I18N_NOOP2( "Permissions", "Append" ) },
 
39
 
 
40
  { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen |
 
41
    KIMAP::Acl::Insert | KIMAP::Acl::Post | KIMAP::Acl::Write |
 
42
    KIMAP::Acl::CreateMailbox | KIMAP::Acl::DeleteMailbox |
 
43
    KIMAP::Acl::DeleteMessage | KIMAP::Acl::Expunge,
 
44
    I18N_NOOP2( "Permissions", "Write" ) },
 
45
 
 
46
  { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen |
 
47
    KIMAP::Acl::Insert | KIMAP::Acl::Post | KIMAP::Acl::Write |
 
48
    KIMAP::Acl::CreateMailbox | KIMAP::Acl::DeleteMailbox |
 
49
    KIMAP::Acl::DeleteMessage | KIMAP::Acl::Expunge | KIMAP::Acl::Admin,
 
50
    I18N_NOOP2( "Permissions", "All" ) }
 
51
};
 
52
 
 
53
uint AclUtils::standardPermissionsCount()
 
54
{
 
55
  return ( sizeof( standardPermissions ) / sizeof( *standardPermissions ) );
 
56
}
 
57
 
 
58
KIMAP::Acl::Rights AclUtils::permissionsForIndex( uint index )
 
59
{
 
60
  Q_ASSERT( index < standardPermissionsCount() );
 
61
 
 
62
  return standardPermissions[ index ].permissions;
 
63
}
 
64
 
 
65
int AclUtils::indexForPermissions( KIMAP::Acl::Rights permissions )
 
66
{
 
67
  const uint maxSize( sizeof( standardPermissions ) / sizeof( *standardPermissions ) );
 
68
  for ( uint i = 0; i < maxSize; ++i ) {
 
69
    if ( KIMAP::Acl::normalizedRights( permissions ) == standardPermissions[i].permissions ) {
 
70
      return i;
 
71
    }
 
72
  }
 
73
 
 
74
  return -1;
 
75
}
 
76
 
 
77
QString AclUtils::permissionsToUserString( KIMAP::Acl::Rights permissions )
 
78
{
 
79
  const uint maxSize( sizeof( standardPermissions ) / sizeof( *standardPermissions ) );
 
80
  for ( uint i = 0; i < maxSize; ++i ) {
 
81
    if ( KIMAP::Acl::normalizedRights( permissions ) == standardPermissions[i].permissions ) {
 
82
      return i18nc( "Permissions", standardPermissions[ i ].userString );
 
83
    }
 
84
  }
 
85
 
 
86
  return i18n( "Custom Permissions (%1)",
 
87
               QString::fromLatin1( KIMAP::Acl::rightsToString( permissions ) ) );
 
88
}