示例#1
0
//-----------------------------------------------------------------------------
// ExecuteScript()
//   Execute the script found within the file.
//-----------------------------------------------------------------------------
static int ExecuteScript(
    const char *fileName)               // name of file containing Python code
{
    PyObject *importer, *dict, *code, *temp;

    if (SetExecutableName(fileName) < 0)
        return -1;
    if (SetPathToSearch() < 0)
        return -1;
    importer = NULL;
    if (GetImporter(&importer) < 0)
        return -1;

    // create and populate dictionary for initscript module
    dict = PyDict_New();
    if (PopulateInitScriptDict(dict) < 0) {
        Py_XDECREF(dict);
        Py_DECREF(importer);
        return -1;
    }

    // locate and execute script
    code = PyObject_CallMethod(importer, "get_code", "s", "cx_Freeze__init__");
    Py_DECREF(importer);
    if (!code)
        return FatalError("unable to locate initialization module");
    temp = PyEval_EvalCode( (EvalCodeType*) code, dict, dict);
    Py_DECREF(code);
    Py_DECREF(dict);
    if (!temp)
        return FatalScriptError();
    Py_DECREF(temp);

    return 0;
}
nsresult
sbWatchFolder::ProcessAddedPaths()
{
  LOG(("%s: Processing the added file paths... [mAddedPaths.size == %i]",
    __FUNCTION__, mAddedPaths.size()));

  if (mAddedPaths.empty()) {
    return NS_OK;
  }

  nsresult rv;
  nsCOMPtr<nsIArray> uriArray;
  rv = GetURIArrayForStringPaths(mAddedPaths, getter_AddRefs(uriArray));
  NS_ENSURE_SUCCESS(rv, rv);

  mAddedPaths.clear();

  PRUint32 uriArrayLength = 0;
  rv = uriArray->GetLength(&uriArrayLength);
  NS_ENSURE_SUCCESS(rv, rv);

  if (uriArrayLength > 0) {
    nsCOMPtr<sbIDirectoryImportService> importService;
    rv = GetImporter(getter_AddRefs(importService));
    NS_ENSURE_SUCCESS(rv, rv);

    //
    // XXX todo This can cause problems if this fires when the user is dragging
    //          and dropping into a playlist. This will need to be fixed.
    //
    nsCOMPtr<sbIDirectoryImportJob> job;
    rv = importService->ImportWithCustomSnifferAndMetadataScanner(
      uriArray,
      mTypeSniffer,
      mMetadataScanner,
      mMediaList,
      -1,
      getter_AddRefs(job));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<sbIJobProgressService> progressService =
      do_GetService("@songbirdnest.com/Songbird/JobProgressService;1", &rv);
    if (NS_SUCCEEDED(rv) && progressService) {
      nsCOMPtr<sbIJobProgress> jobProgress = do_QueryInterface(job, &rv);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = progressService->ShowProgressDialog(jobProgress, nsnull, 1);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }

  return NS_OK;
}
	int FirstPage::nextId () const
	{
		return StartPages_ [GetImporter ()];
	}
nsresult
sbWatchFolder::Rescan()
{
    nsresult rv;

    // Setup the directory scan service.
    nsCOMPtr<sbIDirectoryImportService> dirImportService;
    rv = GetImporter(getter_AddRefs(dirImportService));
    NS_ENSURE_SUCCESS(rv, rv);

    // The directory import service wants the paths as an array.
    nsCOMPtr<nsILocalFile> watchPathFile =
      do_CreateInstance("@mozilla.org/file/local;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = watchPathFile->InitWithPath(mWatchPath);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIMutableArray> dirArray =
      do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);

    rv = dirArray->AppendElement(watchPathFile, PR_FALSE);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<sbIDirectoryImportJob> importJob;
    rv = dirImportService->ImportWithCustomSnifferAndMetadataScanner(
                                  dirArray,
                                  mTypeSniffer,
                                  mMetadataScanner,
                                  mMediaList,
                                  -1,
                                  getter_AddRefs(importJob));
    NS_ENSURE_SUCCESS(rv, rv);

    if (!importJob) {
      return NS_OK;
    }

    if (!mCanInteract) {
      return NS_OK;
    }

    nsCOMPtr<sbIJobProgressService> progressService =
      do_GetService("@songbirdnest.com/Songbird/JobProgressService;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<sbIJobProgress> job = do_QueryInterface(importJob, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<sbIApplicationController> appController =
      do_GetService("@songbirdnest.com/Songbird/ApplicationController;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIDOMWindow> activeWindow;
    rv = appController->GetActiveWindow(getter_AddRefs(activeWindow));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = progressService->ShowProgressDialog(job, activeWindow, 1);
    NS_ENSURE_SUCCESS(rv, rv);

    return NS_OK;
}