Ticket #44882: patchset-RJVB-20141009-against-9ed4f721.diff
File patchset-RJVB-20141009-against-9ed4f721.diff, 51.4 KB (added by RJVB (René Bertin), 10 years ago) |
---|
-
cmake/modules/KDE4Macros.cmake
diff --git cmake/modules/KDE4Macros.cmake cmake/modules/KDE4Macros.cmake index 073d726..ac58d58 100644
macro (KDE4_ADD_KDEINIT_EXECUTABLE _target_NAME ) 836 836 kde4_add_executable(${_target_NAME} "${_nogui}" ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp ${_resourcefile}) 837 837 target_link_libraries(${_target_NAME} kdeinit_${_target_NAME}) 838 838 endif(WIN32) 839 if(_nogui) 840 set_target_properties(kdeinit_${_target_NAME} PROPERTIES COMPILE_FLAGS -DKDE_WITHOUT_GUI) 841 message(STATUS "Building \"kdeinit_${_target_NAME}\" with -DKDE_WITHOUT_GUI because \"${_nogui}\"") 842 endif(_nogui) 839 843 840 844 endmacro (KDE4_ADD_KDEINIT_EXECUTABLE) 841 845 … … macro (KDE4_ADD_EXECUTABLE _target_NAME) 1010 1014 add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS}) 1011 1015 endif (KDE4_ENABLE_FINAL) 1012 1016 1017 if(_nogui) 1018 set_target_properties(${_target_NAME} PROPERTIES COMPILE_FLAGS -DKDE_WITHOUT_GUI) 1019 message(STATUS "Building \"${_target_NAME}\" with -DKDE_WITHOUT_GUI because \"${_nogui}\"") 1020 endif(_nogui) 1021 1013 1022 IF (KDE4_ENABLE_UAC_MANIFEST) 1014 1023 _kde4_add_manifest(${_target_NAME}) 1015 1024 ENDIF(KDE4_ENABLE_UAC_MANIFEST) -
kdeui/actions/kaction.cpp
diff --git kdeui/actions/kaction.cpp kdeui/actions/kaction.cpp index 9e8f7fb..54088d2 100644
KAction::KAction(QObject *parent) 140 140 : QWidgetAction(parent), d(new KActionPrivate) 141 141 { 142 142 d->init(this); 143 setMenuRole(QAction::NoRole); 143 144 } 144 145 145 146 KAction::KAction(const QString &text, QObject *parent) … … KAction::KAction(const QString &text, QObject *parent) 147 148 { 148 149 d->init(this); 149 150 setText(text); 151 setMenuRole(QAction::NoRole); 150 152 } 151 153 152 154 KAction::KAction(const KIcon &icon, const QString &text, QObject *parent) … … KAction::KAction(const KIcon &icon, const QString &text, QObject *parent) 155 157 d->init(this); 156 158 setIcon(icon); 157 159 setText(text); 160 setMenuRole(QAction::NoRole); 158 161 } 159 162 160 163 KAction::~KAction() -
kdeui/kernel/kapplication.cpp
diff --git kdeui/kernel/kapplication.cpp kdeui/kernel/kapplication.cpp index b093034..ec1455f 100644
static int kde_x_errhandler( Display *dpy, XErrorEvent *err ) 138 138 void KApplication_init_windows(); 139 139 #endif 140 140 141 #ifdef KDE_WITHOUT_GUI 142 #define GUIENABLED false 143 #else 144 #define GUIENABLED true 145 #endif //KDE_WITHOUT_GUI 146 141 147 /* 142 148 Private data to make keeping binary compatibility easier 143 149 */ … … public: 205 211 void _k_slot_KToolInvocation_hook(QStringList&, QByteArray&); 206 212 207 213 QString sessionConfigName() const; 208 void init(bool GUIenabled= true);214 void init(bool GUIenabled=GUIENABLED); 209 215 void parseCommandLine( ); // Handle KDE arguments (Using KCmdLineArgs) 216 #ifdef Q_OS_MAC 217 static void preqapplicationhack(bool GUIenabled = GUIENABLED); 218 #else 210 219 static void preqapplicationhack(); 220 #endif 211 221 static void preread_app_startup_id(); 212 222 void read_app_startup_id(); 213 223 … … static SmcConn mySmcConnection = 0; 342 352 #endif 343 353 344 354 KApplication::KApplication(bool GUIenabled) 355 #ifdef Q_OS_MAC 356 : QApplication((KApplicationPrivate::preqapplicationhack(GUIenabled),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), GUIenabled), 357 #else 345 358 : QApplication((KApplicationPrivate::preqapplicationhack(),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), GUIenabled), 359 #endif 346 360 d(new KApplicationPrivate(this)) 347 361 { 348 362 d->read_app_startup_id(); -
kdeui/kernel/kapplication.h
diff --git kdeui/kernel/kapplication.h kdeui/kernel/kapplication.h index fa2ab26..ff17f26 100644
public: 97 97 * <li>Call KGlobal::locale(), if using multiple threads.</li> 98 98 * </ul> 99 99 */ 100 #ifdef KDE_WITHOUT_GUI 101 explicit KApplication(bool GUIenabled = false); 102 #else 100 103 explicit KApplication(bool GUIenabled = true); 104 #endif // KDE_WITHOUT_GUI 101 105 102 106 #ifdef Q_WS_X11 103 107 /** … … public: 134 138 * 135 139 * @param GUIenabled Set to false to disable all GUI stuff. 136 140 */ 141 #ifdef KDE_WITHOUT_GUI 142 KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName, 143 bool GUIenabled=false); 144 #else 137 145 KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName, 138 146 bool GUIenabled=true); 147 #endif // KDE_WITHOUT_GUI 139 148 #endif 140 149 141 150 virtual ~KApplication(); -
kdeui/kernel/kuniqueapplication.h
diff --git kdeui/kernel/kuniqueapplication.h kdeui/kernel/kuniqueapplication.h index e05dcd7..97fd942 100644
public: 65 65 * depend on the value of the "MultipleInstances" 66 66 * key in the "KDE" group of the application config file. 67 67 */ 68 #ifdef KDE_WITHOUT_GUI 69 explicit KUniqueApplication( bool GUIenabled=false, 70 bool configUnique=false); 71 #else 68 72 explicit KUniqueApplication( bool GUIenabled=true, 69 73 bool configUnique=false); 74 #endif //KDE_WITHOUT_GUI 70 75 71 76 #ifdef Q_WS_X11 72 77 /** -
kdeui/notifications/kstatusnotifieritem.cpp
diff --git kdeui/notifications/kstatusnotifieritem.cpp kdeui/notifications/kstatusnotifieritem.cpp index 1b15d40..1ed7de3 100644
bool KStatusNotifierItemPrivate::checkVisibility(QPoint pos, bool perform) 683 683 684 684 return false; 685 685 } 686 #else 687 Q_UNUSED(pos); 688 Q_UNUSED(perform); 686 689 #endif 687 690 688 691 return true; … … void KStatusNotifierItemPrivate::init(const QString &extraId) 745 748 746 749 //create a default menu, just like in KSystemtrayIcon 747 750 KMenu *m = new KMenu(associatedWidget); 751 #ifdef Q_OS_MAC 752 // emulate addTitle/setTitle by adding an inactive menu item. 753 titleAction = m->addAction( qApp->windowIcon(), KGlobal::mainComponent().aboutData()->programName() ); 754 titleAction->setEnabled(false); 755 titleAction->setIconVisibleInMenu(true); 756 m->addAction( titleAction ); 757 m->addSeparator(); 758 kDebug() << "### Added SystemTray titleAction=" << titleAction; 759 kDebug() << "### SystemTray for app" << qApp << "=" << KGlobal::mainComponent().aboutData()->programName() 760 << "/" << KGlobal::caption() << "with icon" << qApp->windowIcon().name(); 761 #else 748 762 titleAction = m->addTitle(qApp->windowIcon(), KGlobal::caption()); 749 763 m->setTitle(KGlobal::mainComponent().aboutData()->programName()); 764 #endif 750 765 q->setContextMenu(m); 751 766 752 767 KStandardAction::quit(q, SLOT(maybeQuit()), actionCollection); -
kdeui/util/kwallet.h
diff --git kdeui/util/kwallet.h kdeui/util/kwallet.h index d7f703f..895868a 100644
class KDEUI_EXPORT Wallet : public QObject 481 481 * @param success True if the wallet was opened successfully. 482 482 */ 483 483 void walletOpened(bool success); 484 485 484 private Q_SLOTS: 486 485 /** 487 486 * @internal -
kdeui/util/kwallet_mac.cpp
diff --git kdeui/util/kwallet_mac.cpp kdeui/util/kwallet_mac.cpp index 8344ebb..3d9c5a8 100644
27 27 #include <kdeversion.h> 28 28 #include <QtGui/QApplication> 29 29 #include <QtCore/QPointer> 30 #include <QtCore/QSharedMemory> 30 31 #include <QtGui/QWidget> 32 #include <QtCore/QTimer> 31 33 #include <ktoolinvocation.h> 32 34 33 35 #include <kglobal.h> … … 39 41 40 42 #include <sys/param.h> 41 43 44 #define IDLETIMER_DEBUG 45 #undef USE_KWALLETD 46 42 47 #include "qosxkeychain.h" 43 48 44 using namespace KWallet; 49 #ifdef USE_KWALLETD 50 # include "kwallet_interface.h" 51 #endif 52 53 #include "kwallet_mac.h" 45 54 46 55 typedef QMap<QString, QString> StringStringMap; 47 56 Q_DECLARE_METATYPE(StringStringMap) … … Q_DECLARE_METATYPE(StringToStringStringMapMap) 50 59 typedef QMap<QString, QByteArray> StringByteArrayMap; 51 60 Q_DECLARE_METATYPE(StringByteArrayMap) 52 61 53 #ifdef OSX_KEYCHAIN_PORT_DISABLED 62 #include <mach/mach.h> 63 #include <mach/mach_time.h> 64 #include <mach/mach_init.h> 65 #include <sys/sysctl.h> 66 67 static mach_timebase_info_data_t sTimebaseInfo; 68 static double calibrator= 0, startTime = 0; 69 static QSharedValue<double> sharedStartTime; 70 71 double HRTime_Time() 72 { 73 return mach_absolute_time() * calibrator - startTime; 74 } 75 76 void init_HRTime() 77 { 78 if( !calibrator ){ 79 mach_timebase_info(&sTimebaseInfo); 80 /* go from absolute time units to seconds (the timebase is calibrated in nanoseconds): */ 81 calibrator= 1e-9 * sTimebaseInfo.numer / sTimebaseInfo.denom; 82 QString key = "kwalletWallClockStartTime"; 83 sharedStartTime.attachOrCreate( key, HRTime_Time() ); 84 sharedStartTime.getValue(startTime); 85 qDebug() << "init_HRTime(): connected to kwalletWallClock at t=" << HRTime_Time(); 86 } 87 } 88 89 namespace KWallet 90 { 91 92 #ifdef USE_KWALLETD 93 class KWalletDLauncher 94 { 95 public: 96 KWalletDLauncher(); 97 ~KWalletDLauncher(); 98 org::kde::KWallet &getInterface(); 99 100 org::kde::KWallet *m_wallet; 101 KConfigGroup m_cgroup; 102 }; 103 104 K_GLOBAL_STATIC(KWalletDLauncher, walletLauncher) 105 static const char s_kwalletdServiceName[] = "org.kde.kwalletd"; 106 107 #else 108 109 /** 110 * maps wallet name to a map of app name to <wallet,pid> instances 111 */ 112 // deserialising the WalletUsersList from a QDataStream works only for a few WalletInstancePtr types 113 // We could store the Wallet* in a QByteArray, but that would make it impossible to dump the WalletUsersList 114 // to the console for debugging. So we use a QVariant. 115 typedef QVariant WalletInstancePtr; 116 // typedef QList<QPair<WalletInstancePtr,pid_t> > WalletUsersListEntryData; 117 class WalletUsersListEntryData : public QList<QPair<WalletInstancePtr,pid_t> > 118 { 119 public: 120 static WalletUsersListEntryData create(QPair<WalletInstancePtr,pid_t> &head) 121 { 122 WalletUsersListEntryData self; 123 self.clear(); 124 self.append(head); 125 return self; 126 } 127 static WalletUsersListEntryData create(QPair<WalletInstancePtr,pid_t> head) 128 { 129 WalletUsersListEntryData self; 130 self.clear(); 131 self.append(head); 132 return self; 133 } 134 }; 135 136 typedef QMap<QString,WalletUsersListEntryData> WalletUsersListEntry; 137 typedef QMap<QString,WalletUsersListEntry> WalletUsersList; 138 static WalletUsersList walletUsers; 139 140 #endif //USE_KWALLETD 141 142 54 143 static QString appid() 55 144 { 56 145 KComponentData cData = KGlobal::mainComponent(); … … static QString appid() 63 152 } 64 153 return qApp->applicationName(); 65 154 } 66 #endif67 155 68 156 /*static*/ const QString Wallet::LocalWallet() 69 157 { … … static QString appid() 104 192 return "Form Data"; 105 193 } 106 194 195 #ifndef USE_KWALLETD 196 static QStringList getUsersFromRegistry(QString &name) 197 { QString app = appid(); 198 QStringList users; 199 users.clear(); 200 if( walletUsers.contains(name) ){ 201 WalletUsersListEntry entry = walletUsers[name]; 202 for( WalletUsersListEntry::const_iterator it = entry.constBegin() ; it != entry.constEnd() ; ++it ){ 203 if( !it.value().isEmpty() ){ 204 users.append(it.key()); 205 } 206 } 207 } 208 return users; 209 } 210 211 static void removeFromRegistry( QString app, QString &name, WalletUsersListEntryData &entries ) 212 { 213 for( WalletUsersListEntryData::const_iterator it = entries.constBegin() ; it != entries.constEnd() ; ++it ){ 214 QPair<WalletInstancePtr,pid_t> wdat = *it; 215 if( walletUsers.contains(name) && walletUsers[name].contains(app) ){ 216 WalletUsersListEntry entry = walletUsers[name]; 217 WalletUsersListEntryData appInstances = entry[app]; 218 if( appInstances.contains(wdat) ){ 219 appInstances.removeAll(wdat); 220 qDebug() << "removing application instance" << wdat << "from registry"; 221 } 222 if( appInstances.isEmpty() ){ 223 entry.remove(app); 224 qDebug() << "removing application" << app << "from registry"; 225 } 226 else{ 227 entry[app] = appInstances; 228 } 229 if( entry[app].isEmpty() ){ 230 walletUsers.remove(name); 231 qDebug() << "removing wallet" << name << "from registry"; 232 } 233 else{ 234 walletUsers[name] = entry; 235 } 236 } 237 } 238 } 239 #endif //USE_KWALLETD 240 107 241 #pragma mark ==== Wallet::WalletPrivate ==== 108 class Wallet::WalletPrivate : public OSXKeychain 242 Wallet::WalletPrivate::WalletPrivate(Wallet *wallet, const QString &n, int h) 243 : OSXKeychain(n, &isNew), q(wallet), handle(h) 244 , idleTimer(NULL) 245 #ifdef IDLETIMER_DEBUG 246 , idleTimerTriggered(0) 247 #endif 248 , lastConfigCheckTime(-1) 109 249 { 110 public: 111 explicit WalletPrivate(const QString &n) 112 : OSXKeychain(n) 113 { 114 isKDEChain = ( n == LocalWallet() || n == NetworkWallet() || n.contains( "wallet", Qt::CaseInsensitive ) ); 250 isKDEChain = ( n == LocalWallet() || n == NetworkWallet() || n.contains( "wallet", Qt::CaseInsensitive ) ); 251 if( !calibrator ){ 252 init_HRTime(); 253 } 254 if( isKDEChain ){ 255 if( !lastAccessTime.attachOrCreate( (QString&)n, QSharedMemory::ReadWrite) ){ 256 qDebug() << "Couldn't create shared lastAccessTime member for wallet" << n 257 << "; idle timeouts will be per-client. Error" << lastAccessTime.errorString(); 258 } 259 handleIdleTiming(__FUNCTION__); 115 260 } 261 } 262 Wallet::WalletPrivate::~WalletPrivate() 263 { 264 #ifndef USE_KWALLETD 265 removeFromRegistry(); 266 #endif //USE_KWALLETD 267 deleteIdleTimer(); 268 } 116 269 117 // needed for compilation reasons 118 void walletServiceUnregistered() 119 { 270 #ifndef USE_KWALLETD 271 void Wallet::WalletPrivate::addToRegistry() 272 { QString app = appid(); 273 QPair<WalletInstancePtr,pid_t> wdat = qMakePair(QVariant((qulonglong)q),getpid()); 274 if( !walletUsers.contains(name) ){ 275 // Unknown wallet name, so there ought not be an existing QMap<appName,walletInstanceList> 276 WalletUsersListEntryData detail; 277 detail.clear(); 278 detail.append(wdat); 279 WalletUsersListEntry entry; 280 entry.clear(); 281 entry[app] = detail; 282 walletUsers[name] = entry; 120 283 } 121 }; 284 else{ 285 WalletUsersListEntry entry = walletUsers[name]; 286 WalletUsersListEntryData detail; 287 if( entry.contains(app) ){ 288 detail = entry[app]; 289 } 290 else{ 291 detail.clear(); 292 } 293 detail.append(wdat); 294 entry[app] = detail; 295 walletUsers[name] = entry; 296 } 297 QByteArray mapData; 298 QDataStream ds(&mapData, QIODevice::WriteOnly); 299 ds << walletUsers; 300 qDebug() << "@@@" << HRTime_Time() << "Added" << wdat << "for app" << app << "to wallet" << name << "in registry of len=" << mapData.length() << walletUsers; 301 } 302 303 void Wallet::WalletPrivate::removeFromRegistry() 304 { 305 WalletUsersListEntryData entries = WalletUsersListEntryData::create(qMakePair(QVariant((qulonglong)q),getpid())); 306 KWallet::removeFromRegistry( appid(), name, entries ); 307 } 308 309 QStringList Wallet::WalletPrivate::getUsersFromRegistry() 310 { 311 return KWallet::getUsersFromRegistry(name); 312 } 313 #endif //USE_KWALLETD 314 315 void Wallet::WalletPrivate::close() 316 { 317 // // close the keychain wallet but only if we get here through the kwalletmanager 318 // // or TODO if wallets should be closed when the last client disconnects 319 // // and we are the last client. 320 // if( appid() == "KDE Wallet Manager" ){ 321 deleteIdleTimer(); 322 OSXKeychain::close(); 323 // } 324 } 325 326 OSStatus Wallet::WalletPrivate::lock() 327 { 328 if( idleTimer ){ 329 idleTimer->stop(); 330 } 331 return Lock(reference()); 332 } 333 334 void Wallet::WalletPrivate::walletServiceUnregistered() 335 { 336 #ifdef USE_KWALLETD 337 if( handle >= 0 ){ 338 q->slotWalletClosed(handle); 339 } 340 #endif 341 } 342 343 void Wallet::WalletPrivate::deleteIdleTimer() 344 { 345 if( idleTimer ){ 346 idleTimer->stop(); 347 idleTimer->deleteLater(); 348 idleTimer = NULL; 349 } 350 } 351 352 // This function is to be called at every operation that is supposed to launch or reset 353 // the idle timing. 354 void Wallet::WalletPrivate::handleIdleTiming(const char *caller, bool touchAccessTime) 355 { 356 if( !isKDEChain ){ 357 return; 358 } 359 double now = HRTime_Time(); 360 if( lastConfigCheckTime < 0 || (now - lastConfigCheckTime >= 10) ){ 361 lastConfigCheckTime = now; 362 KConfigGroup cfg(KSharedConfig::openConfig("kwalletrc")->group("Wallet")); 363 if (cfg.readEntry("Close When Idle", true)) { 364 timeOut = cfg.readEntry( "Idle Timeout", ((int)0) ); 365 if( caller && idleTimer ){ 366 qDebug() << "###" << caller << "->handleIdleTiming: setting" << idleTimer << "for wallet" << name << "handle" << handle << "timeout to" << timeOut; 367 } 368 } 369 else{ 370 timeOut = -1; 371 } 372 } 373 if( timeOut >= 0 ){ 374 if( !idleTimer ){ 375 idleTimer = new QTimer(0); 376 connect( idleTimer, SIGNAL(timeout()), this, SLOT(slotIdleTimedOut()), Qt::DirectConnection ); 377 } 378 else{ 379 idleTimer->stop(); 380 } 381 // when the idle timer fires, the wallet is supposed to be closed. There is thus 382 // no reason to use a repeating timer. 383 idleTimer->setSingleShot(true); 384 if( touchAccessTime ){ 385 if( !lastAccessTime.setValue(HRTime_Time()) ){ 386 qDebug() << "Cannot set new lastAccessTime for wallet" << name << "error" << lastAccessTime.errorString(); 387 } 388 } 389 idleTimer->start( timeOut * 60 * 1000 ); 390 } 391 else{ 392 timeOut = -1; 393 deleteIdleTimer(); 394 } 395 } 396 397 void Wallet::WalletPrivate::slotIdleTimedOut() 398 { double lastTime = 0; 399 // check the last time anyone accessed this wallet: 400 if( !lastAccessTime.getValue(lastTime) ){ 401 qDebug() << "Cannot get lastAccessTime for wallet" << name << "error" << lastAccessTime.errorString(); 402 } 403 // the time elapsed since that last access, in minutes: 404 double elapsed = (HRTime_Time() - lastTime) / 60; 405 #ifdef IDLETIMER_DEBUG 406 idleTimerTriggered += 1; 407 qDebug() << "###" << HRTime_Time() << appid() << "Idle timeout" << timeOut << "min. for" << q << name << "handle" << handle 408 << "; elapsed minutes=" << elapsed << "timer" << idleTimer << "triggered" << idleTimerTriggered << "times"; 409 #endif //IDLETIMER_DEBUG 410 if( elapsed >= timeOut ){ 411 // we have a true timeout, i.e. we didn't access the wallet in timeOut minutes, and no one else did either. 412 q->slotWalletClosed(handle); 413 } 414 else{ 415 // false alarm, reset the timer, but there's no need to count this as an access! 416 handleIdleTiming(__FUNCTION__, false); 417 } 418 } 122 419 123 420 Wallet::Wallet(int handle, const QString& name) 124 : QObject(0L), d(new WalletPrivate( name))421 : QObject(0L), d(new WalletPrivate(this, name, handle)) 125 422 { 126 Q_UNUSED(handle); 423 #ifdef USE_KWALLETD 424 QDBusServiceWatcher *watcher = new QDBusServiceWatcher(QString::fromLatin1(s_kwalletdServiceName), QDBusConnection::sessionBus(), 425 QDBusServiceWatcher::WatchForUnregistration, this); 426 connect(watcher, SIGNAL(serviceUnregistered(QString)), 427 d, SLOT(walletServiceUnregistered())); 428 429 connect(&walletLauncher->getInterface(), SIGNAL(walletClosed(int)), SLOT(slotWalletClosed(int))); 430 connect(&walletLauncher->getInterface(), SIGNAL(folderListUpdated(QString)), SLOT(slotFolderListUpdated(QString))); 431 connect(&walletLauncher->getInterface(), SIGNAL(folderUpdated(QString,QString)), SLOT(slotFolderUpdated(QString,QString))); 432 connect(&walletLauncher->getInterface(), SIGNAL(applicationDisconnected(QString,QString)), SLOT(slotApplicationDisconnected(QString,QString))); 433 #else 434 d->addToRegistry(); 435 #endif // USE_KWALLETD 436 if( d->handle != handle ){ 437 qDebug() << "Wallet::Wallet(" << name << ") handle changed from" << handle << "to" << d->handle; 438 } 127 439 } 128 440 129 441 Wallet::~Wallet() … … Wallet::~Wallet() 172 484 #ifdef OSX_KEYCHAIN_PORT_DISABLED 173 485 return walletLauncher->getInterface().isOpen(name); // default is false 174 486 #else 487 #ifdef USE_KWALLETD 488 walletLauncher->getInterface().isOpen(name); 489 #endif // USE_KWALLETD 175 490 return OSXKeychain::IsOpen(name); 176 491 #endif 177 492 } … … bool Wallet::isOpen() const 181 496 #ifdef OSX_KEYCHAIN_PORT_DISABLED 182 497 return d->handle != -1; 183 498 #else 499 d->handleIdleTiming(__FUNCTION__); 500 501 #ifdef USE_KWALLETD 502 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(d->name); 503 #endif // USE_KWALLETD 184 504 return d->isOpen(); 185 505 #endif 186 506 } … … bool Wallet::isOpen() const 193 513 return r.isValid() ? r : -1; 194 514 #else 195 515 Q_UNUSED(force); 196 return OSXKeychain::Lock(name); 516 #ifdef USE_KWALLETD 517 QDBusReply<int> r = walletLauncher->getInterface().close(name, force); 518 #endif // USE_KWALLETD 519 // emit a signal that we just closed the wallet 520 Wallet(0, name).slotWalletClosed(0); 521 return OSXKeychain::IsOpen(name); 197 522 #endif 198 523 } 199 524 … … bool Wallet::isOpen() const 213 538 { 214 539 Q_UNUSED(w); 215 540 Q_UNUSED(ot); 216 Wallet *wallet = new Wallet(-1, name); 217 QMetaObject::invokeMethod( wallet, "emitWalletOpened", Qt::QueuedConnection ); 218 OSStatus err = wallet->d->unLock(); 219 kDebug() << "Opened wallet '" << name << "': " << wallet << " error=" << err; 541 Wallet *wallet = new Wallet((int)w, name); 542 if( wallet ){ 543 #ifdef USE_KWALLETD 544 // connect the daemon's opened signal to the slot filtering the 545 // signals we need 546 connect(&walletLauncher->getInterface(), SIGNAL(walletAsyncOpened(int,int)), 547 wallet, SLOT(walletAsyncOpened(int,int))); 548 #endif 549 OSStatus err = wallet->d->unLock(); 550 if( !err && wallet->d->isKDEChain && wallet->d->isNew ){ 551 wallet->d->setLockSettings( false, 0 ); 552 } 553 kDebug() << "Opened wallet '" << name << "': " << wallet << " error=" << err; 554 #ifdef USE_KWALLETD 555 wallet->emitWalletOpened(); 556 #else 557 QMetaObject::invokeMethod( wallet, "emitWalletOpened", Qt::QueuedConnection ); 558 #endif 559 } 220 560 return wallet; 221 561 } 222 562 … … bool Wallet::isOpen() const 226 566 #ifdef OSX_KEYCHAIN_PORT_DISABLED 227 567 return walletLauncher->getInterface().disconnectApplication(wallet, app); // default is false 228 568 #else 229 kWarning() << "Wallet::disconnectApplication unimplemented, '" << app << "' from '" << wallet << "'"; 230 return true; 569 kWarning() << "Wallet::disconnectApplication unimplemented, '" << app << "' from '" << wallet << "'" 570 #ifdef USE_KWALLETD 571 << walletLauncher->getInterface().disconnectApplication(wallet, app) 572 #endif // USE_KWALLETD 573 ; 574 // app disconnect is done/possible only when the app in question closes its wallet. 575 return false; 231 576 #endif 232 577 } 233 578 … … bool Wallet::isOpen() const 237 582 #ifdef OSX_KEYCHAIN_PORT_DISABLED 238 583 return walletLauncher->getInterface().users(name); // default is QStringList() 239 584 #else 240 kWarning() << "Wallet::users unimplemented, '" << name << "'"; 241 return QStringList(); 585 #ifdef USE_KWALLETD 586 QStringList ul = walletLauncher->getInterface().users(name); 587 kWarning() << "Wallet::users unimplemented, '" << name << "'" << ul; 588 return ul; 589 #else 590 return KWallet::getUsersFromRegistry((QString&)name); 591 #endif // USE_KWALLETD 242 592 #endif 243 593 } 244 594 … … int Wallet::sync() 250 600 return -1; 251 601 } 252 602 253 walletLauncher->getInterface().sync(d->handle, appid());254 603 #endif 604 d->handleIdleTiming(__FUNCTION__); 605 606 #ifdef USE_KWALLETD 607 walletLauncher->getInterface().sync(d->handle, appid()); 608 #endif // USE_KWALLETD 255 609 return 0; 256 610 } 257 611 … … int Wallet::lockWallet() 272 626 } 273 627 #else 274 628 d->currentService.clear(); 629 d->handle = -1; 275 630 #endif 276 return d->lock(); 631 d->lock(); 632 emit walletClosed(); 633 return 1; 277 634 } 278 635 279 636 280 637 const QString& Wallet::walletName() const 281 638 { 639 d->handleIdleTiming(__FUNCTION__); 282 640 return d->name; 283 641 } 284 642 … … void Wallet::requestChangePassword(WId w) 295 653 walletLauncher->getInterface().changePassword(d->name, (qlonglong)w, appid()); 296 654 #else 297 655 Q_UNUSED(w); 656 d->handleIdleTiming(__FUNCTION__); 298 657 kWarning() << "Wallet::requestChangePassword unimplemented '" << d->name << "'"; 299 658 #endif 300 659 } … … void Wallet::slotWalletClosed(int handle) 310 669 emit walletClosed(); 311 670 } 312 671 #else 313 Q_UNUSED(handle); 314 kWarning() << "Wallet::slotWalletClosed unimplemented '" << d->name << "'"; 315 d->currentService.clear(); 672 // kWarning() << "Wallet::slotWalletClosed unimplemented '" << d->name << "'"; 673 if( d->handle == handle ){ 674 d->handle = -1; 675 d->currentService.clear(); 676 kDebug() << "Wallet::slotWalletClosed '" << d->name << "'"; 677 // TODO remove ourselves from the WalletUsersList here! 678 d->close(); 679 emit walletClosed(); 680 } 681 else{ 682 qDebug() << "Wallet::slotWalletClosed '" << d->name << "' ignored because handle" << d->handle << "!=" << handle; 683 } 316 684 #endif 317 685 } 318 686 … … QStringList Wallet::folderList() 327 695 QDBusReply<QStringList> r = walletLauncher->getInterface().folderList(d->handle, appid()); 328 696 return r; 329 697 #else 698 d->handleIdleTiming(__FUNCTION__); 330 699 return QStringList(d->folderList()); 331 700 #endif 332 701 } … … QStringList Wallet::entryList() 342 711 QDBusReply<QStringList> r = walletLauncher->getInterface().entryList(d->handle, d->folder, appid()); 343 712 return r; 344 713 #else 714 d->handleIdleTiming(__FUNCTION__); 715 345 716 QStringList r = QStringList(); 346 717 d->itemList(r); 347 718 return r; … … bool Wallet::hasFolder(const QString& f) 359 730 QDBusReply<bool> r = walletLauncher->getInterface().hasFolder(d->handle, f, appid()); 360 731 return r; // default is false 361 732 #else 733 d->handleIdleTiming(__FUNCTION__); 362 734 d->folderList(); 363 735 return d->serviceList.contains(f); 364 736 #endif … … bool Wallet::createFolder(const QString& f) 379 751 380 752 return true; // folder already exists 381 753 #else 754 d->handleIdleTiming(__FUNCTION__); 382 755 return setFolder(f); 383 756 #endif 384 757 } … … bool Wallet::setFolder(const QString &f) 407 780 408 781 return rc; 409 782 #else 783 d->handleIdleTiming(__FUNCTION__); 410 784 // act as if we just changed folders even if we have no such things; the property 411 785 // is stored as the ServiceItemAttr (which shows up as the "Where" field in the Keychain Utility). 412 786 if( f.size() == 0 ){ … … bool Wallet::removeFolder(const QString& f) 434 808 435 809 return r; // default is false 436 810 #else 811 d->handleIdleTiming(__FUNCTION__); 437 812 kWarning() << "Wallet::removeFolder unimplemented (returns true) '" << d->name << "'"; 438 813 if( d->currentService == f ){ 439 814 d->currentService.clear(); … … const QString& Wallet::currentFolder() const 448 823 #ifdef OSX_KEYCHAIN_PORT_DISABLED 449 824 return d->folder; 450 825 #else 826 d->handleIdleTiming(__FUNCTION__); 451 827 return d->currentService; 452 828 #endif 453 829 } 454 830 455 831 456 832 int Wallet::readEntry(const QString &key, QByteArray &value) 457 { OSStatus err = d->readItem( key, &value, NULL ); 833 { OSStatus err; 834 d->handleIdleTiming(__FUNCTION__); 835 err = d->readItem( key, &value, NULL ); 458 836 kDebug() << "Wallet::readEntry '" << key << "' from wallet " << d->name << ", error=" << ((err)? -1 : 0); 459 837 return (err)? -1 : 0; 460 838 } … … int Wallet::readEntryList(const QString& key, QMap<QString, QByteArray>& value) 485 863 #else 486 864 Q_UNUSED(key); 487 865 Q_UNUSED(value); 866 d->handleIdleTiming(__FUNCTION__); 488 867 kWarning() << "Wallet::readEntryList unimplemented (returns -1) '" << d->name << "'"; 489 868 return -1; 490 869 #endif … … int Wallet::renameEntry(const QString& oldName, const QString& newName) 507 886 508 887 return rc; 509 888 #else 889 d->handleIdleTiming(__FUNCTION__); 510 890 return d->renameItem( oldName, newName ); 511 891 #endif 512 892 } … … int Wallet::renameEntry(const QString& oldName, const QString& newName) 514 894 515 895 int Wallet::readMap(const QString &key, QMap<QString,QString> &value) 516 896 { 897 d->handleIdleTiming(__FUNCTION__); 898 517 899 QByteArray v; 518 900 const int ret = (d->readItem( key, &v, NULL ))? -1 : 0; 519 901 if( ret != 0 ){ … … int Wallet::readMapList(const QString& key, QMap<QString, QMap<QString, QString> 560 942 #else 561 943 Q_UNUSED(key); 562 944 Q_UNUSED(value); 945 d->handleIdleTiming(__FUNCTION__); 563 946 kWarning() << "Wallet::readMapList unimplemented (returns -1) '" << d->name << "'"; 564 947 return -1; 565 948 #endif … … int Wallet::readMapList(const QString& key, QMap<QString, QMap<QString, QString> 568 951 569 952 int Wallet::readPassword(const QString& key, QString& value) 570 953 { 954 d->handleIdleTiming(__FUNCTION__); 955 571 956 QByteArray ba; 572 957 const int ret = (d->readItem( key, &ba, NULL ))? -1 : 0; 573 958 if ( ret == 0 ){ … … int Wallet::readPasswordList(const QString& key, QMap<QString, QString>& value) 582 967 { 583 968 Q_UNUSED(key); 584 969 Q_UNUSED(value); 970 d->handleIdleTiming(__FUNCTION__); 585 971 kWarning() << "Wallet::readPasswordList unimplemented (returns -1) '" << d->name << "'"; 586 972 return -1; 587 973 } 588 974 589 975 int Wallet::writeEntry(const QString& key, const QByteArray& password ) 590 { int ret = d->writeItem( key, password ); 976 { int ret; 977 d->handleIdleTiming(__FUNCTION__); 978 ret = d->writeItem( key, password ); 591 979 kDebug() << "wrote entry '" << key << "' to wallet " << d->name << ", error=" << ret; 592 980 return ret; 593 981 } 594 982 595 983 int Wallet::writeEntry(const QString& key, const QByteArray& password, EntryType entryType) 596 984 { 985 d->handleIdleTiming(__FUNCTION__); 986 597 987 OSXKeychain::EntryType entryCode; 598 988 switch( entryType ){ 599 989 case Wallet::Password: … … int Wallet::writeEntry(const QString& key, const QByteArray& password, EntryType 616 1006 617 1007 int Wallet::writeMap(const QString& key, const QMap<QString,QString>& value) 618 1008 { 1009 d->handleIdleTiming(__FUNCTION__); 1010 619 1011 QByteArray mapData; 620 1012 QDataStream ds(&mapData, QIODevice::WriteOnly); 621 1013 ds << value; … … int Wallet::writeMap(const QString& key, const QMap<QString,QString>& value) 630 1022 631 1023 632 1024 int Wallet::writePassword(const QString &key, const QString& value) 633 { OSXKeychain::EntryType etype = OSXKeychain::Password; 1025 { OSXKeychain::EntryType etype; 1026 1027 d->handleIdleTiming(__FUNCTION__); 1028 etype = OSXKeychain::Password; 634 1029 int ret = d->writeItem( key, value.toUtf8(), &etype ); 635 1030 kDebug() << "wrote password '" << key << "' to wallet " << d->name << ", error=" << ret; 636 1031 return ret; … … int Wallet::writePassword(const QString &key, const QString& value) 638 1033 639 1034 640 1035 bool Wallet::hasEntry(const QString &key) 641 { bool ret = d->hasItem( key, NULL ); 1036 { bool ret; 1037 1038 d->handleIdleTiming(__FUNCTION__); 1039 ret = d->hasItem( key, NULL ); 642 1040 kDebug() << "wallet '" << d->name << "'" << ((ret)? " has" : " does not have") << " entry '" << key << "'"; 643 1041 return ret; 644 1042 } 645 1043 646 1044 int Wallet::removeEntry(const QString& key) 647 { int ret = d->removeItem( key ); 1045 { int ret; 1046 1047 d->handleIdleTiming(__FUNCTION__); 1048 ret = d->removeItem( key ); 648 1049 kDebug() << "removed entry '" << key << "' from wallet " << d->name << ", error=" << ret; 649 1050 return ret; 650 1051 } … … Wallet::EntryType Wallet::entryType(const QString& key) 666 1067 667 1068 return static_cast<EntryType>(rc); 668 1069 #else 1070 d->handleIdleTiming(NULL); 1071 669 1072 // RJVB: a priori, entries are always 'password' on OS X, but since we also do use them for storing 670 1073 // maps, it may be best to return Wallet::Unknown to leave some uncertainty and not mislead our caller. 671 1074 OSXKeychain::EntryType etype; … … Wallet::EntryType Wallet::entryType(const QString& key) 690 1093 void Wallet::slotFolderUpdated(const QString& wallet, const QString& folder) 691 1094 { 692 1095 if (d->name == wallet) { 1096 kDebug() << "emit folderUpdated" << folder; 693 1097 emit folderUpdated(folder); 694 1098 } 695 1099 } … … void Wallet::slotFolderUpdated(const QString& wallet, const QString& folder) 698 1102 void Wallet::slotFolderListUpdated(const QString& wallet) 699 1103 { 700 1104 if (d->name == wallet) { 1105 kDebug() << "emit foldeListrUpdated" << wallet; 701 1106 emit folderListUpdated(); 702 1107 } 703 1108 } … … void Wallet::slotFolderListUpdated(const QString& wallet) 705 1110 706 1111 void Wallet::slotApplicationDisconnected(const QString& wallet, const QString& application) 707 1112 { 708 #ifdef OSX_KEYCHAIN_PORT_DISABLED 709 if (d->handle >= 0 1113 #ifdef USE_KWALLETD 1114 qDebug() << "slotApplicationDisconnected(" << wallet << "," << application << "); handle=" 1115 << d->handle << "name=" << d->name << "appid=" << appid(); 1116 if( d->handle >= 0 710 1117 && d->name == wallet 711 && application == appid()) { 1118 && application == appid() 1119 ){ 712 1120 slotWalletClosed(d->handle); 713 1121 } 714 1122 #else 715 1123 Q_UNUSED(wallet); 716 1124 Q_UNUSED(application); 717 kWarning() << "Wallet::slotApplicationDisconnected unimplemented '" << d->name << "'"; 718 #endif 1125 #endif //USE_KWALLETD 719 1126 } 720 1127 721 1128 void Wallet::walletAsyncOpened(int tId, int handle) … … void Wallet::walletAsyncOpened(int tId, int handle) 733 1140 emit walletOpened(handle > 0); 734 1141 #else 735 1142 Q_UNUSED(tId); 736 Q_UNUSED(handle); 737 kWarning() << "Wallet::walletAsyncOpened unimplemented '" << d->name << "'"; 1143 d->handleIdleTiming(__FUNCTION__); 1144 #ifdef USE_KWALLETD 1145 // disconnect the async signal 1146 disconnect(this, SLOT(walletAsyncOpened(int,int))); 1147 qDebug() << "walletAsyncOpened: emit walletOpened(true), handle=" << handle; 1148 emit walletOpened(true); 1149 #endif // USE_KWALLETD 1150 d->handle = handle; 738 1151 #endif 739 1152 } 740 1153 741 1154 void Wallet::emitWalletAsyncOpenError() 742 1155 { 1156 d->handleIdleTiming(__FUNCTION__); 1157 kDebug() << "emitWalletAsyncOpenError: emit walletOpened(false)"; 743 1158 emit walletOpened(false); 744 1159 } 745 1160 746 1161 void Wallet::emitWalletOpened() 747 1162 { 748 emit walletOpened(true); 1163 d->handleIdleTiming(__FUNCTION__); 1164 kDebug() << "emitWalletOpened: emit walletOpened(true)"; 1165 emit walletOpened(true); 749 1166 } 750 1167 751 1168 752 bool Wallet::folderDoesNotExist(const QString& wallet, const QString& folder)1169 /*static*/ bool Wallet::folderDoesNotExist(const QString& wallet, const QString& folder) 753 1170 { 754 1171 #ifdef OSX_KEYCHAIN_PORT_DISABLED 755 1172 QDBusReply<bool> r = walletLauncher->getInterface().folderDoesNotExist(wallet, folder); … … bool Wallet::folderDoesNotExist(const QString& wallet, const QString& folder) 764 1181 } 765 1182 766 1183 767 bool Wallet::keyDoesNotExist(const QString& wallet, const QString& folder, const QString& key)1184 /*static*/ bool Wallet::keyDoesNotExist(const QString& wallet, const QString& folder, const QString& key) 768 1185 { 769 1186 #ifdef OSX_KEYCHAIN_PORT_DISABLED 770 1187 QDBusReply<bool> r = walletLauncher->getInterface().keyDoesNotExist(wallet, folder, key); … … bool Wallet::keyDoesNotExist(const QString& wallet, const QString& folder, const 784 1201 void Wallet::slotCollectionStatusChanged(int status) 785 1202 { 786 1203 Q_UNUSED(status); 787 kWarning() << "Wallet::slotCollectionStatusChanged unimplemented '" << d->name << "' status=" << status; 1204 d->handleIdleTiming(__FUNCTION__); 1205 kWarning() << "Wallet::slotCollectionStatusChanged unimplemented '" << d->name << "' status=" << status; 788 1206 } 789 1207 790 1208 void Wallet::slotCollectionDeleted() … … void Wallet::slotCollectionDeleted() 795 1213 d->currentService.clear(); 796 1214 #endif 797 1215 kDebug() << "Wallet::slotCollectionDeleted: closing private data '" << d->name; 1216 // TODO remove ourselves from the WalletUsersList here! 798 1217 d->close(); 799 1218 emit walletClosed(); 800 1219 } … … void Wallet::virtual_hook(int, void*) 805 1224 //BASE::virtual_hook( id, data ); 806 1225 } 807 1226 1227 #ifdef USE_KWALLETD 1228 KWalletDLauncher::KWalletDLauncher() 1229 : m_wallet(0), 1230 m_cgroup(KSharedConfig::openConfig("kwalletrc", KConfig::NoGlobals)->group("Wallet")) 1231 { 1232 m_wallet = new org::kde::KWallet(QString::fromLatin1(s_kwalletdServiceName), "/modules/kwalletd", QDBusConnection::sessionBus()); 1233 } 1234 1235 KWalletDLauncher::~KWalletDLauncher() 1236 { 1237 delete m_wallet; 1238 } 1239 1240 org::kde::KWallet &KWalletDLauncher::getInterface() 1241 { 1242 Q_ASSERT(m_wallet != 0); 1243 1244 // check if kwalletd is already running 1245 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) 1246 { 1247 // not running! check if it is enabled. 1248 bool walletEnabled = m_cgroup.readEntry("Enabled", true); 1249 if (walletEnabled) { 1250 // wallet is enabled! try launching it 1251 QString error; 1252 int ret = KToolInvocation::startServiceByDesktopPath("kwalletd.desktop", QStringList(), &error); 1253 if (ret > 0){ 1254 kError(285) << "Couldn't start kwalletd: " << error << endl; 1255 } 1256 1257 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) { 1258 kDebug(285) << "The kwalletd service is still not registered"; 1259 } else { 1260 kDebug(285) << "The kwalletd service has been registered"; 1261 } 1262 } else { 1263 kError(285) << "The kwalletd service has been disabled"; 1264 } 1265 } 1266 1267 return *m_wallet; 1268 } 1269 #endif //USE_KWALLETD 1270 1271 } // namespace KWallet 1272 1273 #include "kwallet_mac.moc" 808 1274 #include "kwallet.moc" -
kdeui/util/qosxkeychain.cpp
diff --git kdeui/util/qosxkeychain.cpp kdeui/util/qosxkeychain.cpp index 7cb9a22..708c728 100644
OSXKeychain::OSXKeychain() 161 161 serviceList.append(""); 162 162 } 163 163 164 OSXKeychain::OSXKeychain(const QString &n )164 OSXKeychain::OSXKeychain(const QString &n, bool *isNew) 165 165 : name(n) 166 166 { QString errMsg; 167 167 OSStatus err = openKeychain( n, &keyChainRef ); … … OSXKeychain::OSXKeychain(const QString &n) 170 170 kWarning() << "Keychain '" << n << "' does not exist: attempting to create it"; 171 171 err = SecKeychainCreate( n.toUtf8(), 0, NULL, true, NULL, &keyChainRef ); 172 172 isKDEChain = true; 173 if( !err && isNew ){ 174 *isNew = true; 175 } 176 } 177 else if( !err && isNew ){ 178 *isNew = false; 173 179 } 174 180 175 181 if( isError( err, &errMsg ) ){ … … OSXKeychain::OSXKeychain(const QString &n) 197 203 void OSXKeychain::close() 198 204 { 199 205 if( keyChainRef ){ 206 Lock(keyChainRef); 200 207 CFRelease(keyChainRef); 201 208 keyChainRef = NULL; 209 serviceList.clear(); 202 210 } 203 211 } 204 212 205 213 OSXKeychain::~OSXKeychain() 206 214 { 207 close(); 215 if( keyChainRef ){ 216 CFRelease(keyChainRef); 217 keyChainRef = NULL; 218 } 219 serviceList.clear(); 220 } 221 222 OSStatus OSXKeychain::lockSettings(int &closeWhenIdle, unsigned int &idleTimeoutMin) 223 { QString errMsg; 224 SecKeychainSettings kcSettings= { SEC_KEYCHAIN_SETTINGS_VERS1, 0, 0, INT_MAX }; 225 OSStatus err = SecKeychainCopySettings( keyChainRef, &kcSettings ); 226 if( isError( err, &errMsg ) ){ 227 kWarning() << "Error getting settings for" << name << err << "=" << qPrintable(errMsg); 228 } 229 else{ 230 closeWhenIdle = kcSettings.useLockInterval; 231 idleTimeoutMin = (int)(kcSettings.lockInterval / 60 + 0.5); 232 } 233 return err; 234 } 235 236 OSStatus OSXKeychain::setLockSettings(int closeWhenIdle, unsigned int idleTimeoutMin) 237 { QString errMsg; 238 SecKeychainSettings kcSettings = { SEC_KEYCHAIN_SETTINGS_VERS1, 0, 0, INT_MAX }; 239 OSStatus err; 240 241 // to switch (or keep) off idle timeout locking set useLockInterval=false and lockInterval=INT_MAX 242 // if lockInterval has any other value, SecKeychainSetSettings() will force useLockInterval=true 243 if( closeWhenIdle ){ 244 kcSettings.useLockInterval = 1; 245 kcSettings.lockInterval = idleTimeoutMin * 60; 246 } 247 err = SecKeychainSetSettings( keyChainRef, &kcSettings ); 248 // if( !err ){ 249 // SecKeychainSettings ks = { SEC_KEYCHAIN_SETTINGS_VERS1, 0, 0, INT_MAX }; 250 // ks.useLockInterval = !closeWhenIdle; 251 // SecKeychainCopySettings( keyChainRef, &ks ); 252 // qDebug() << "Keychain settings set to useLockInterval=" << ks.useLockInterval << "lockInterval=" << ks.lockInterval; 253 // } 254 // else{ 255 // qDebug() << "Error setting keychain settings:" << err; 256 // } 257 return err; 208 258 } 209 259 210 260 OSStatus OSXKeychain::renameItem(const QString ¤tKey, const QString &newKey) … … OSStatus OSXKeychain::Lock(const QString &walletName) 330 380 OSStatus err = openKeychain( walletName, &keychain ); 331 381 if( !err && keychain ){ 332 382 err = Lock(keychain); 333 383 CFRelease(keychain); 334 384 } 335 385 return err; 336 386 } … … bool OSXKeychain::HasItem(const QString &key, 377 427 *errReturn = err; 378 428 } 379 429 } 380 kDebug() << ((found)? "Found" : "Did not find") << "item '" << key<< "' in keychain " << (void*) keychain << ", error=" << err << " " << qPrintable(errMsg);430 kDebug() << "item '" << key << ((found)? "found" : "not found") << "' in keychain " << (void*) keychain << ", error=" << err << " " << qPrintable(errMsg); 381 431 return found; 382 432 } 383 433 -
kdeui/util/qosxkeychain.h
diff --git kdeui/util/qosxkeychain.h kdeui/util/qosxkeychain.h index d0934e6..7370418 100644
18 18 * Boston, MA 02110-1301, USA. 19 19 */ 20 20 21 #ifndef _QOSXKEYCHAIN_H 22 21 23 #include <Security/Security.h> 22 24 #include <Security/SecKeychain.h> 23 25 … … namespace { 59 61 } 60 62 61 63 static inline QString asQString( CFStringRef sr ) 62 { CFIndex len = CFStringGetLength(sr)*2; 63 const CPPArrayDeleter<char*> buff(new char[len]); 64 if( CFStringGetCString( sr, buff.ptr, len, kCFStringEncodingUTF8 ) ){ 65 return QString::fromUtf8(buff.ptr); //RJVB: use UTF8 66 } 67 else if( CFStringGetCString( sr, buff.ptr, len, kCFStringEncodingNonLossyASCII ) ){ 68 return QString::fromLocal8Bit(buff.ptr); 64 { 65 if( sr ){ 66 CFIndex len = CFStringGetLength(sr)*2; 67 const CPPArrayDeleter<char*> buff(new char[len]); 68 if( CFStringGetCString( sr, buff.ptr, len, kCFStringEncodingUTF8 ) ){ 69 return QString::fromUtf8(buff.ptr); //RJVB: use UTF8 70 } 71 else if( CFStringGetCString( sr, buff.ptr, len, kCFStringEncodingNonLossyASCII ) ){ 72 return QString::fromLocal8Bit(buff.ptr); 73 } 74 else{ 75 CFStringGetCString( sr, buff.ptr, len, NULL ); 76 return QString::fromLatin1(buff.ptr); 77 } 69 78 } 70 79 else{ 71 CFStringGetCString( sr, buff.ptr, len, NULL ); 72 return QString::fromLatin1(buff.ptr); 80 return QString(); 73 81 } 74 82 } 75 83 … … static inline bool isError( OSStatus s, QString *errMsg ) 87 95 return s != 0; 88 96 } 89 97 90 class OSXKeychain 98 class OSXKeychain //: protected QObject 91 99 { 100 // Q_OBJECT 92 101 private: 93 102 SecKeychainRef keyChainRef; 94 103 QString keyChainPath; … … public: 102 111 bool isKDEChain; 103 112 104 113 OSXKeychain(); 105 OSXKeychain(const QString &name );114 OSXKeychain(const QString &name, bool *isNew=NULL); 106 115 virtual ~OSXKeychain(); 107 116 108 117 inline SecKeychainRef reference() … … public: 119 128 } 120 129 inline bool isOpen() 121 130 { 122 return IsOpen(keyChainRef); 131 // we're either a KDE wallet/keychain and we have a valid keyChainRef, 132 // or we're not KDE and IsOpen will return the state of the default 133 // keychain if keyChainRef==NULL. 134 if( !isKDEChain || keyChainRef ){ 135 return IsOpen(keyChainRef); 136 } 137 else{ 138 return false; 139 } 123 140 } 124 141 inline OSStatus lock() 125 142 { 126 return Lock(keyChainRef); 143 if( !isKDEChain || keyChainRef ){ 144 return Lock(keyChainRef); 145 } 146 else{ 147 return 0; 148 } 127 149 } 128 150 inline OSStatus unLock() 129 151 { 130 return UnLock(keyChainRef); 152 if( !isKDEChain || keyChainRef ){ 153 return UnLock(keyChainRef); 154 } 155 else{ 156 return 0; 157 } 131 158 } 132 void close(); 159 virtual void close(); 160 OSStatus lockSettings(int &closeWhenIdle, unsigned int &idleTimeoutMin); 161 OSStatus setLockSettings(int closeWhenIdle, unsigned int idleTimeoutMin); 133 162 inline bool hasItem(const QString &key, OSStatus *errReturn, SecKeychainItemRef *itemRef=NULL) 134 163 { 135 // qDebug() << "OSXKeychain::hasItem(" << key << "): scanning '" << name << "'=" << (void*) keyChainRef; 136 return OSXKeychain::HasItem( key, keyChainRef, errReturn, itemRef ); 164 if( !isKDEChain || keyChainRef ){ 165 return OSXKeychain::HasItem( key, keyChainRef, errReturn, itemRef ); 166 } 167 else{ 168 return false; 169 } 137 170 } 138 171 inline OSStatus readItem(const QString &key, QByteArray *value, SecKeychainItemRef *itemRef=NULL) 139 172 { 140 return ReadItem( key, value, keyChainRef, itemRef, this ); 173 if( !isKDEChain || keyChainRef ){ 174 return ReadItem( key, value, keyChainRef, itemRef, this ); 175 } 176 else{ 177 return 0; 178 } 141 179 } 142 180 inline OSStatus itemType(const QString &key, EntryType *entryType) 143 181 { 144 return ItemType( key, entryType, keyChainRef ); 182 if( !isKDEChain || keyChainRef ){ 183 return ItemType( key, entryType, keyChainRef ); 184 } 185 else{ 186 return 0; 187 } 145 188 } 146 189 inline OSStatus removeItem(const QString &key) 147 190 { 148 return RemoveItem( key, keyChainRef ); 191 if( !isKDEChain || keyChainRef ){ 192 return RemoveItem( key, keyChainRef ); 193 } 194 else{ 195 return 0; 196 } 149 197 } 150 198 inline OSStatus writeItem( const QString &key, const QByteArray &value, EntryType *entryType=NULL ) 151 199 { 152 return WriteItem( key, value, keyChainRef, NULL, entryType, this ); 200 if( !isKDEChain || keyChainRef ){ 201 return WriteItem( key, value, keyChainRef, NULL, entryType, this ); 202 } 203 else{ 204 return 0; 205 } 153 206 } 154 207 inline OSStatus writeItem( const QString &key, const QByteArray &value, const QString &comment, 155 208 EntryType *entryType=NULL ) 156 209 { 157 return WriteItem( key, value, comment, keyChainRef, entryType, this ); 210 if( !isKDEChain || keyChainRef ){ 211 return WriteItem( key, value, comment, keyChainRef, entryType, this ); 212 } 213 else{ 214 return 0; 215 } 158 216 } 159 217 inline OSStatus itemList( QStringList &keyList ) 160 218 { 161 return ItemList( keyChainRef, keyList, this ); 219 if( !isKDEChain || keyChainRef ){ 220 return ItemList( keyChainRef, keyList, this ); 221 } 222 else{ 223 return 0; 224 } 162 225 } 163 226 inline QStringList folderList() 164 227 { 165 QStringList r; 166 CacheOldValue<bool> gFL(generateFolderList, true); 167 ItemList( keyChainRef, r, this ); 168 r.clear(); 169 return serviceList; 228 if( !isKDEChain || keyChainRef ){ 229 QStringList r; 230 CacheOldValue<bool> gFL(generateFolderList, true); 231 ItemList( keyChainRef, r, this ); 232 r.clear(); 233 return serviceList; 234 } 235 else{ 236 return QStringList(); 237 } 170 238 } 171 239 OSStatus renameItem(const QString ¤tKey, const QString &newKey); 172 240 … … public: 197 265 static OSStatus ItemList( const SecKeychainRef keychain, QStringList &keyList, OSXKeychain *osxKeyChain=NULL ); 198 266 static OSStatus Destroy( SecKeychainRef *keychain ); 199 267 static OSStatus Destroy( const QString &walletName ); 268 269 // private Q_SLOTS: 270 // virtual void slotIdleTimedOut() 271 // {} 200 272 }; 273 274 #define _QOSXKEYCHAIN_H 275 #endif 276 No newline at end of file -
kdeui/widgets/kmenu.cpp
diff --git kdeui/widgets/kmenu.cpp kdeui/widgets/kmenu.cpp index 7dab149..9b64236 100644
42 42 #include <klocale.h> 43 43 #include <kacceleratormanager.h> 44 44 45 #ifdef Q_OS_MAC 46 #include <kmainwindow.h> 47 #include <kmenubar.h> 48 #endif //Q_OS_MAC 49 45 50 static const char KMENU_TITLE[] = "kmenu_title"; 46 51 47 52 class KMenu::KMenuPrivate … … QAction* KMenu::addTitle(const QString &text, QAction* before) 172 177 return addTitle(QIcon(), text, before); 173 178 } 174 179 180 #ifdef Q_OS_MAC 181 static bool isMenubarMenu(QMenu *m) 182 { bool ret = false; 183 static int level = -1; 184 QList<QMenu*> checkList; 185 level += 1; 186 if (m && m->menuAction()) { 187 QAction *mAct = m->menuAction(); 188 qDebug() << "##" << level << "isMenubarMenu(" << m << m->title() << ") menuAction=" << mAct << mAct->text(); 189 foreach (QWidget *w, mAct->associatedWidgets()) { 190 if (w == m) { 191 goto done; 192 } 193 qDebug() << "###" << level << "associated widget" << w << w->windowTitle() << "parent=" << w->parentWidget(); 194 if (QMenuBar *mb = qobject_cast<QMenuBar*>(w)) { 195 qDebug() << "#### widget is QMenuBar" << mb << mb->windowTitle() << "with parent" << mb->parentWidget(); 196 ret = true; 197 goto done; 198 } 199 else if (QMenu *mm = qobject_cast<QMenu*>(w)) { 200 if (checkList.contains(mm)) { 201 continue; 202 } 203 checkList.append(mm); 204 qDebug() << "####" << level << "widget is QMenu" << mm << mm->title() << "with parent" << mm->parentWidget(); 205 if (isMenubarMenu(mm)) { 206 ret = true; 207 goto done; 208 } 209 } 210 } 211 } 212 done:; 213 level -= 1; 214 return ret; 215 } 216 #endif 217 175 218 QAction* KMenu::addTitle(const QIcon &icon, const QString &text, QAction* before) 176 219 { 177 QAction *buttonAction = new QAction(this); 178 QFont font = buttonAction->font(); 179 font.setBold(true); 180 buttonAction->setFont(font); 181 buttonAction->setText(text); 182 buttonAction->setIcon(icon); 183 184 QWidgetAction *action = new QWidgetAction(this); 185 action->setObjectName(KMENU_TITLE); 186 QToolButton *titleButton = new QToolButton(this); 187 titleButton->installEventFilter(d); // prevent clicks on the title of the menu 188 titleButton->setDefaultAction(buttonAction); 189 titleButton->setDown(true); // prevent hover style changes in some styles 190 titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 191 action->setDefaultWidget(titleButton); 192 193 insertAction(before, action); 220 #ifdef Q_OS_MAC 221 bool isMacMenuBar = isMenubarMenu(this); 222 #else 223 bool isMacMenuBar = false; 224 #endif // Q_OS_MAC 225 QAction *action = new QAction(this); 226 action->setText(text); 227 action->setIcon(icon); 228 #ifdef Q_OS_MAC 229 if (isMacMenuBar) { 230 action->setEnabled(false); 231 if (before && actions().contains(before)) { 232 QAction *sepLow = new QAction(this); 233 sepLow->setSeparator(true); 234 insertAction(before, sepLow); 235 insertAction(sepLow, action); 236 if (!actions().startsWith(action)) { 237 QAction *sepHigh = new QAction(this); 238 sepHigh->setSeparator(true); 239 insertAction(action,sepHigh); 240 qDebug() << "#### inserted high separator before" << action << action->text() << "before low separator before" << before; 241 } 242 else{ 243 qDebug() << "#### inserted" << action << action->text() << "before low separator before" << before; 244 } 245 } 246 else{ 247 if (actions().size()) { 248 addSeparator(); 249 } 250 addAction(action); 251 addSeparator(); 252 qDebug() << "#### appended low separator after" << action << action->text() << "after existing" << actions().size()-2 << "items (before=" << before; 253 } 254 } 255 else 256 #endif // Q_OS_MAC 257 { 258 QFont font = action->font(); 259 font.setBold(true); 260 action->setFont(font); 261 262 QWidgetAction *styledAction = new QWidgetAction(this); 263 styledAction->setObjectName(KMENU_TITLE); 264 QToolButton *titleButton = new QToolButton(this); 265 titleButton->installEventFilter(d); // prevent clicks on the title of the menu 266 titleButton->setDefaultAction(action); 267 titleButton->setDown(true); // prevent hover style changes in some styles 268 titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 269 styledAction->setDefaultWidget(titleButton); 270 271 insertAction(before, styledAction ); 272 action = styledAction; 273 } 194 274 return action; 195 275 } 196 276