Ejemplo n.º 1
0
System::System(JNIEnv *env, jobject nidroid) 
{
    m_JNIScope = new jnipp::Env::Scope(env);
    jnipp::Ref<jnipp::Object> nidroidRef(nidroid);
    
    m_Nidroid.set(nidroidRef);
    m_NidroidClass.set(nidroidRef->getClass());

    jnipp::StaticMethod<jdouble> getPixelRatio(m_NidroidClass, "getPixelRatio", "()D");
    jnipp::StaticMethod<jnipp::String> getUserDirectory(m_NidroidClass, "getUserDirectory", "()Ljava/lang/String;");
    jnipp::StaticMethod<jnipp::String> getLanguage(m_NidroidClass, "getLanguage", "()Ljava/lang/String;");
    jnipp::Method<jnipp::String> getCacheDirectory(m_NidroidClass, "getCacheDirectory", "()Ljava/lang/String;");

    m_PixelRatio = getPixelRatio();
    m_UserDirectory = getUserDirectory()->str();
    m_CacheDirectory = getCacheDirectory(m_Nidroid)->str();
    m_Language = getLanguage()->str();

#ifdef NDM_ANDROID_DEVELOPMENT
    static const char embedDir[] = "/nidium/Embed/";
    size_t size = (strlen(m_UserDirectory) + strlen(embedDir) + 1);
    m_EmbedDirectory = (char *)malloc(sizeof(char) * size);
    snprintf(m_EmbedDirectory, size, "%s%s", m_UserDirectory, embedDir);
#else
    static const char embedDir[] = "/nidium/Embed/";
    size_t size = (strlen(m_CacheDirectory) + strlen(embedDir) + 1);
    m_EmbedDirectory = (char *)malloc(sizeof(char) * size);
    snprintf(m_EmbedDirectory, size, "%s%s", m_CacheDirectory, embedDir);
#endif
}
Ejemplo n.º 2
0
void CinderNativeActivity::launchTwitter( const std::string& text, const Surface8u* surf )
{
	std::string pathStr = "";
	if( nullptr != surf ) {
		try {
			cinder::fs::path path = getCacheDirectory() / "launchTwitter_tmp_image.png";
			pathStr = path.string();
			cinder::writeImage( path, *surf );
		}
		catch( const std::exception& e ) {
			dbg_app_error( std::string( "launchTwitter temp image write failed: " ) + e.what() );
		}
	}

	jstring jstrText = JniHelper::Get()->NewStringUTF( text );
	jstring jstrPath = JniHelper::Get()->NewStringUTF( pathStr );
	JniHelper::Get()->CallVoidMethod( getInstance()->getJavaObject(), Java::launchTwitter, jstrText, jstrPath );
	JniHelper::Get()->DeleteLocalRef( jstrText );
	JniHelper::Get()->DeleteLocalRef( jstrPath );
}
Ejemplo n.º 3
0
void CinderNativeActivity::setWallpaper( const Surface8u& surf )
{
	std::string pathStr = "";

	try {
		cinder::fs::path path = getCacheDirectory() / "setWallpaper_tmp_image.png";
		pathStr = path.string();
		cinder::writeImage( path, surf );
	}
	catch( const std::exception& e ) {
		pathStr = "";
		dbg_app_error( std::string( "setWallpaper temp image write failed: " ) + e.what() );
	}

	if( ! pathStr.empty() ) {
		jstring jstrPath = JniHelper::Get()->NewStringUTF( pathStr );
		JniHelper::Get()->CallVoidMethod( getInstance()->getJavaObject(), Java::setWallpaper, jstrPath );
		JniHelper::Get()->DeleteLocalRef( jstrPath );
	}
}
Ejemplo n.º 4
0
BEGIN_NAMESPACE

CacheSyncSource::CacheSyncSource(const WCHAR* sourceName, AbstractSyncSourceConfig *sc, KeyValueStore* cache) :
                    SyncSource(sourceName, sc) {
   
    allKeys = NULL;
    newKeys = NULL; 
    updatedKeys = NULL; 
    deletedKeys = NULL;   

    if (cache) {
        this->cache = cache;
    } else {
        // get the default directory of the 
        StringBuffer completeName = getCacheDirectory();;
        completeName += "/";
        completeName += CACHE_FILE_NAME;   

        this->cache = new PropertyFile(completeName);
    }
}
Ejemplo n.º 5
0
void QgsWFSUtils::releaseCacheDirectory()
{
  QMutexLocker locker( &sMutex );
  sCounter --;
  if ( sCounter == 0 )
  {
    if ( sThread )
    {
      sThread->exit();
      sThread->wait();
      delete sThread;
      sThread = nullptr;
    }

    // Destroys our cache directory, and the main cache directory if it is empty
    QString tmpDirname( getCacheDirectory( false ) );
    if ( QDir( tmpDirname ).exists() )
    {
      QgsDebugMsg( QString( "Removing our cache dir %1" ).arg( tmpDirname ) );
      removeDir( tmpDirname );

      QString baseDirname( getBaseCacheDirectory( false ) );
      QDir baseDir( baseDirname );
      QFileInfoList fileList( baseDir.entryInfoList( QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files ) );
      if ( fileList.size() == 0 )
      {
        QgsDebugMsg( QString( "Removing main cache dir %1" ).arg( baseDirname ) );
        removeDir( baseDirname );
      }
      else
      {
        QgsDebugMsg( QString( "%1 entries remaining in %2" ).arg( fileList.size() ).arg( baseDirname ) );
      }
    }
  }
}
Ejemplo n.º 6
0
/**
 * Get a cache filename.
 * @param cache_key Cache key. (Will be filtered using filterCacheKey().)
 * @return Cache filename, or empty string on error.
 */
string CacheManager::getCacheFilename(const string &cache_key)
{
	// Filter invalid characters from the cache key.
	const string filtered_cache_key = filterCacheKey(cache_key);
	if (filtered_cache_key.empty()) {
		// Invalid cache key.
		return string();
	}

	// Get the cache filename.
	// This is the cache directory plus the cache key.
	string cache_filename = getCacheDirectory();

	if (cache_filename.empty())
		return string();
	if (cache_filename.at(cache_filename.size()-1) != DIR_SEP_CHR)
		cache_filename += DIR_SEP_CHR;

	// Append the filtered cache key.
	cache_filename += filtered_cache_key;

	// Cache filename created.
	return cache_filename;
}
Ejemplo n.º 7
0
QString QgsWFSUtils::acquireCacheDirectory()
{
  return getCacheDirectory( true );
}
Ejemplo n.º 8
0
void MediaFrame::get(QJSValue successCallback, QJSValue errorCallback)
{
    int size = m_allFiles.count() - 1;

    QString path;
    QString errorMessage = QString("");
    QJSValueList args;

    if(size < 1) {
        if(size == 0) {
            path = m_allFiles.at(0);

            if(successCallback.isCallable())
            {
                args << QJSValue(path);
                successCallback.call(args);
            }
            return;
        } else {
            errorMessage = "No files available";
            qWarning() << errorMessage;

            args << QJSValue(errorMessage);
            errorCallback.call(args);
            return;
        }
    }

    if(m_random) {
        path = m_allFiles.at(this->random(0, size));
    } else {
        path = m_allFiles.at(m_next);
        m_next++;
        if(m_next > size)
        {
            qDebug() << "Resetting next count from" << m_next << "due to queue size" << size;
            m_next = 0;
        }

    }

    QUrl url = QUrl(path);

    if(url.isValid()) {
        QString localPath = url.toString(QUrl::PreferLocalFile);

        if (!isFile(localPath)) {
            m_filename = path.section('/', -1);

            QString cachedFile = getCacheDirectory()+QLatin1Char('/')+hash(path)+QLatin1Char('_')+m_filename;

            if(isFile(cachedFile)) {
                // File has been cached
                qDebug() << path << "is cached as" << cachedFile;

                if(successCallback.isCallable()) {
                    args << QJSValue(cachedFile);
                    successCallback.call(args);
                }
                return;
            }

            m_successCallback = successCallback;
            m_errorCallback = errorCallback;
            m_filename = cachedFile;

            qDebug() << path << "doesn't exist locally, trying remote.";

            KIO::StoredTransferJob * job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo);
            connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotFinished(KJob*)));

        } else {