void Win32TrayItem::HandleLeftClick()
	{
		if (callback.isNull())
			return;

		try
		{
			ValueList args;
			callback->Call(args);
		}
		catch (ValueException& e)
		{
			Logger* logger = Logger::Get("UI.Win32TrayItem");
			SharedString ss = e.DisplayString();
			logger->Error("Tray icon callback failed: %s", ss->c_str());
		}
	}
예제 #2
0
void TrayClickedCallback(GtkStatusIcon *status_icon, gpointer data)
{
    TrayItemGtk* item = static_cast<TrayItemGtk*>(data);
    KMethodRef cb = item->GetCallback();

    if (cb.isNull())
        return;

    try {
        ValueList args;
        cb->Call(args);

    } catch (ValueException& e) {
        Logger* logger = Logger::Get("UI.TrayItemGtk");
        SharedString ss = e.DisplayString();
        logger->Error("Tray icon callback failed: %s", ss->c_str());
    }
}
예제 #3
0
	void MonkeyBinding::EvaluateUserScript(
		SharedKObject event, std::string& url,
		SharedKObject windowObject, std::string& scriptSource)
	{
		static Logger *logger = Logger::Get("Monkey");
		// I got a castle in brooklyn, that's where i dwell
		// Word, brother.

		if (!windowObject->Get("eval")->IsMethod())
		{
			logger->Error("Found a window object without an "
				"eval function (%s) -- aborting", url.c_str());
			return;
		}

		SharedKObject target = event->GetObject("target");
		if (!windowObject->Get(GLOBAL_NS_VARNAME)->IsObject() &&
			!target.isNull() && target->Get("insertAPI")->IsMethod())
		{
			logger->Info("Forcing Titanium API into: %s\n", url.c_str());
			target->CallNS("insertAPI", Value::NewObject(windowObject));
		}

		SharedKMethod evalFunction = windowObject->GetMethod("eval");
		logger->Info("Loading userscript for %s\n", url.c_str());
		try
		{
			evalFunction->Call(Value::NewString(scriptSource));
		}
		catch (ValueException &ex)
		{
			SharedString ss = ex.DisplayString();
			int line = -1;
			if (ex.GetValue()->IsObject() &&
				ex.GetValue()->ToObject()->Get("line")->IsNumber())
			{
				line = ex.GetValue()->ToObject()->Get("line")->ToInt();
			}
			logger->Error(
				"Exception generated evaluating user script for %s "
				"(line %i): %s", url.c_str(), line, ss->c_str());
		}
	}
예제 #4
0
    std::string TiURLToPath(const std::string& tiURL)
    {
        try
        {
            Poco::URI inURI = Poco::URI(tiURL);

            if (inURI.getScheme() != "ti")
            {
                return tiURL;
            }

            std::string host(inURI.getHost());
            SharedApplication app = Host::GetInstance()->GetApplication();
            std::string path(app->GetComponentPath(host));

            if (path.empty())
            {
                throw ValueException::FromString("Could not find component "+host);
            }

            std::vector<std::string> segments;
            inURI.getPathSegments(segments);

            for (size_t i = 0; i < segments.size(); i++)
            {
                path = FileUtils::Join(path.c_str(), segments[i].c_str(), NULL);
            }
            return path;
        }
        catch (ValueException& e)
        {
            SharedString ss = e.DisplayString();
            Logger* log = Logger::Get("URLUtils");
            log->Error("Could not convert %s to a path: %s", tiURL.c_str(), ss->c_str());
        }
        catch (...)
        {
            Logger* log = Logger::Get("URLUtils");
            log->Error("Could not convert %s to a path", tiURL.c_str());
        }
        return tiURL;
    }
예제 #5
0
    std::string URLToPath(const std::string& url)
    {
        Poco::URI inURI = Poco::URI(url);
        try
        {
            if (url == BlankPageURL())
            {
                return BlankURLToFilePath();
            }
            if (inURI.getScheme() == "ti")
            {
                return TiURLToPath(url);
            }
            else if (inURI.getScheme() == "app")
            {
                return AppURLToPath(url);
            }
            else if (inURI.getScheme().empty())
            {
                // There is no scheme for this URL, so we have to/ guess at this point if
                // it's a path or a relative app:// URL. If a file can be found, assume thi
                // is a file path.
                if (FileUtils::IsFile(url))
                    return url;

                // Otherwise treat this like an app:// URL relative to the root.
                std::string newURL("app://");
                newURL.append(url);
                return AppURLToPath(newURL);
            }
        }
        catch (ValueException& e)
        {
            SharedString ss = e.DisplayString();
            Logger* log = Logger::Get("URLUtils");
            log->Error("Could not convert %s to a path: %s", url.c_str(), ss->c_str());
        }
        return url;
    }
예제 #6
0
	std::string URLToPath(std::string& url)
	{
		Poco::URI inURI = Poco::URI(url);
		try
		{
			if (inURI.getScheme() == "ti")
			{
				return TiURLToPath(url);
			}
			else if (inURI.getScheme() == "app")
			{
				return AppURLToPath(url);
			}
		}
		catch (ValueException& e)
		{
			SharedString ss = e.DisplayString();
			Logger* log = Logger::Get("URLUtils");
			log->Error("Could not convert %s to a path: %s", url.c_str(), ss->c_str());
		}
		return url;
	}
예제 #7
0
    std::string AppURLToPath(const std::string& inURL)
    {
        try
        {
            Poco::URI inURI = Poco::URI(inURL);
            if (inURI.getScheme() != "app")
            {
                return inURL;
            }

            std::string appURL(NormalizeAppURL(inURL));
            inURI = Poco::URI(appURL);

            SharedApplication app = Host::GetInstance()->GetApplication();
            std::string path(app->GetResourcesPath());

            std::vector<std::string> segments;
            inURI.getPathSegments(segments);
            for (size_t i = 0; i < segments.size(); i++)
            {
                path = FileUtils::Join(path.c_str(), segments[i].c_str(), NULL);
            }
            return path;
        }
        catch (ValueException& e)
        {
            SharedString ss = e.DisplayString();
            Logger* log = Logger::Get("URLUtils");
            log->Error("Could not convert %s to a path: %s", inURL.c_str(), ss->c_str());
        }
        catch (...)
        {
            Logger* log = Logger::Get("URLUtils");
            log->Error("Could not convert %s to a path", inURL.c_str());
        }

        return inURL;
    }
예제 #8
0
void Network::NetworkStatusChange(bool online)
{
    static Logger* log = Logger::Get("NetworkStatus");
    log->Debug("ti.Network: Online status changed ==> %i", online);
    this->Set("online", Value::NewBool(online));

    ValueList args = ValueList();
    args.push_back(Value::NewBool(online));
    std::vector<Listener>::iterator it = this->listeners.begin();
    while (it != this->listeners.end())
    {
        KMethodRef callback = (*it++).callback;
        try
        {
            RunOnMainThread(callback, args, false);
        }
        catch(ValueException& e)
        {
            SharedString ss = e.GetValue()->DisplayString();
            log->Error("Network.NetworkStatus callback failed: %s", ss->c_str());
        }
    }
}
예제 #9
0
KValueRef KObject::Get(SharedString name)
{
    return this->Get(name->c_str());
}
예제 #10
0
void KObject::Set(SharedString name, KValueRef value)
{
    this->Set(name->c_str(), value);
}
예제 #11
0
파일: host.cpp 프로젝트: jonnymind/kroll
	int Host::Run()
	{
		if (this->waitForDebugger)
		{
#ifdef OS_WIN32
			DebugBreak();
#else
			printf("Waiting for debugger (Press Any Key to Continue pid=%i)...\n", getpid());
			getchar();
#endif
		}

		try
		{
			ScopedLock lock(&moduleMutex);
			this->AddModuleProvider(this);
			this->LoadModules();
		}
		catch (ValueException e)
		{
			SharedString ss = e.GetValue()->DisplayString();
			logger->Error(*ss);
			return 1;
		}

		// Depending on the implementation of platform-specific host,
		// it may block in Start() or implement a UI loop which will
		// be continually called until this->running becomes false.
		try
		{
			this->running = this->Start();
			if (this->runUILoop) 
			{
				while (this->running)
				{
					if (!this->RunLoop())
					{
						break;
					}
				}
			}
		}
		catch (kroll::ValueException& e)
		{
			SharedString s = e.GetValue()->DisplayString();
			logger->Error("Caught exception in main loop: %s", s->c_str());
		}

		ScopedLock lock(&moduleMutex);
		this->Stop();
		this->UnloadModuleProviders();
		this->UnloadModules();

		this->globalObject = NULL;

		// Stop the profiler, if it was enabled
		StopProfiling();

		logger->Notice("Exiting with exit code: %i", exitCode);

		Logger::Shutdown();
		return this->exitCode;
	}