bool SciDoc::save(QString& error) { // LOGGER; if ( isNoname() ) { error = "This is a Noname file and shouldn't be saved directly"; return false; } if ( MainSettings::get(MainSettings::StripTrailingSpaces) ) stripTrailingSpaces(); bool result; stopWatcher(); QFile file(fileName()); if ( file.open(QIODevice::WriteOnly) ) { QString text(""); text = int_->edit1_->text(); file.write(codec()->fromUnicode(text)); file.close(); // Document::save(error); int_->edit1_->setModified(false); result = true; } else { error = tr("Can't open file for writing"); result = false; } startWatcher(); return result; }
JNIEXPORT void JNICALL Java_com_congnt_ndkguide_Store_finalizeStore( JNIEnv* pEnv, jobject pThis) { stopWatcher(pEnv, &mStoreWatcher); StoreEntry* lEntry = mStore.mEntries; StoreEntry* lEntryEnd = lEntry + mStore.mLength; while (lEntry < lEntryEnd) { free(lEntry->mKey); releaseEntryValue(pEnv, lEntry); ++lEntry; } mStore.mLength = 0; }
int Utils::StyleSheetLoader::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: load((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 1: unload(); break; case 2: reload(); break; case 3: startWatcherOnActiveFile(); break; case 4: stopWatcher(); break; default: ; } _id -= 5; } return _id; }
void startWatcher(JNIEnv* pEnv, StoreWatcher* pWatcher, Store* pStore, jobject pStoreFront) { // Erases the StoreWatcher structure. memset(pWatcher, 0, sizeof(StoreWatcher)); pWatcher->mState = STATE_OK; pWatcher->mStore = pStore; // Caches the VM. if ((*pEnv)->GetJavaVM(pEnv, &pWatcher->mJavaVM) != JNI_OK) { goto ERROR; } // Caches classes. pWatcher->ClassStore = (*pEnv)->FindClass(pEnv, "com/congnt/ndkguide/Store"); makeGlobalRef(pEnv, &pWatcher->ClassStore); if (pWatcher->ClassStore == NULL) goto ERROR; pWatcher->ClassColor = (*pEnv)->FindClass(pEnv, "com/congnt/ndkguide/Color"); makeGlobalRef(pEnv, &pWatcher->ClassColor); if (pWatcher->ClassColor == NULL) goto ERROR; // Caches Java methods. pWatcher->MethodOnAlertInt = (*pEnv)->GetMethodID(pEnv, pWatcher->ClassStore, "onAlert", "(I)V"); if (pWatcher->MethodOnAlertInt == NULL) goto ERROR; pWatcher->MethodOnAlertString = (*pEnv)->GetMethodID(pEnv, pWatcher->ClassStore, "onAlert", "(Ljava/lang/String;)V"); if (pWatcher->MethodOnAlertString == NULL) goto ERROR; pWatcher->MethodOnAlertColor = (*pEnv)->GetMethodID(pEnv, pWatcher->ClassStore, "onAlert", "(Lcom/packtpub/Color;)V"); if (pWatcher->MethodOnAlertColor == NULL) goto ERROR; pWatcher->MethodColorEquals = (*pEnv)->GetMethodID(pEnv, pWatcher->ClassColor, "equals", "(Ljava/lang/Object;)Z"); if (pWatcher->MethodColorEquals == NULL) goto ERROR; jmethodID ConstructorColor = (*pEnv)->GetMethodID(pEnv, pWatcher->ClassColor, "<init>", "(Ljava/lang/String;)V"); if (ConstructorColor == NULL) goto ERROR; // Caches objects. pWatcher->mStoreFront = (*pEnv)->NewGlobalRef(pEnv, pStoreFront); if (pWatcher->mStoreFront == NULL) goto ERROR; // Initializes and launches the native thread. For simplicity // purpose, error results are not checked (but we should...). pthread_attr_t lAttributes; int lError = pthread_attr_init(&lAttributes); if (lError) goto ERROR; lError = pthread_create(&pWatcher->mThread, &lAttributes, runWatcher, pWatcher); if (lError) goto ERROR; // Creates a new white color and keeps a global reference. jstring lColor = (*pEnv)->NewStringUTF(pEnv, "white"); if (lColor == NULL) goto ERROR; pWatcher->mColor = (*pEnv)->NewObject(pEnv, pWatcher->ClassColor, ConstructorColor, lColor); makeGlobalRef(pEnv, &pWatcher->mColor); if (pWatcher->mColor == NULL) goto ERROR; return; ERROR: stopWatcher(pEnv, pWatcher); return; }