Exemplo n.º 1
0
/**
 * Check if the popupFileDirectory exists and if the permissions are ok.
 * Should return true in almost every situation.
 */
bool KLinPopup::checkPopupFileDirectory()
{
	QDir dir(POPUP_DIR);
	if (! dir.exists()) {
		int tmpYesNo =  KMessageBox::warningYesNo(this, i18n("Working directory /var/lib/klinpopup/ does not exist!\n"
															 "Shall I create it? (May need root password)"));
		if (tmpYesNo == KMessageBox::Yes) {
			QStringList kdesuArgs;
			kdesuArgs += "-c";
			kdesuArgs += "mkdir -p -m 0777 /var/lib/klinpopup";
			if (KApplication::kdeinitExecWait("kdesu", kdesuArgs) == 0) return true;
		}
	} else {
		KFileItem tmpFileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, "/var/lib/klinpopup");
		mode_t tmpPerms = tmpFileItem.permissions();

		#ifdef MY_EXTRA_DEBUG
		kdDebug() << tmpPerms << endl;
		#endif

		if (tmpPerms != 0777) {

			kdDebug() << "Perms not ok!" << endl;

			int tmpYesNo =  KMessageBox::warningYesNo(this, i18n("Permissions of the working directory /var/lib/klinpopup/ are wrong!\n"
																 "Fix? (May need root password)"));
			if (tmpYesNo == KMessageBox::Yes) {
				QStringList kdesuArgs;
				kdesuArgs += "-c";
				kdesuArgs += "chmod 0777 /var/lib/klinpopup";
				if (KApplication::kdeinitExecWait("kdesu", kdesuArgs) == 0)
					return true;
			}
		} else {
			return true;
		}
	}

	int tmpContinueQuit = KMessageBox::warningYesNo(this,
													i18n("There is a serious problem with the working directory!\n"
														 "Only sending messages will work, "
														 "else you can manually fix and restart KLinPopup."),
													i18n("Warning"),
													i18n("&Continue"),
													i18n("&Quit"),
													"ShowWarningContinueQuit");
	if (tmpContinueQuit != KMessageBox::Yes) slotQuit();

	return false;
}