Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
Core Class Reference

#include <Core.h>

Inheritance diagram for Core:
Inheritance graph
[legend]
Collaboration diagram for Core:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSISESSIONROAMING 
Core ()
PRBool IsRoaming ()
const nsCStringArray * GetFilesToRoam ()
nsresult GetProfileDir (nsIFile **result)
PRInt32 GetMethod ()
nsresult ConflictResolveUI (PRBool download, const nsCStringArray &files, nsCStringArray *result)
nsresult GetRegistry (nsCOMPtr< nsIRegistry > &result)
nsresult GetRegistryTree (nsRegistryKey &result)
nsresult RestoreNet ()
nsresult CloseNet ()
void BeginSession ()
void EndSession ()
boolean isRoaming ()

Protected Member Functions

nsresult ReadRoamingPrefs ()
ProtocolCreateMethodHandler ()
nsresult RestoreCloseNet (PRBool restore)

Protected Attributes

PRBool mIsRoaming
PRInt32 mMethod
nsCStringArray mFiles
nsCOMPtr< nsIRegistrymRegistry

Detailed Description

Definition at line 67 of file Core.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSISESSIONROAMING Core::Core ( )

Member Function Documentation

nsresult Core::CloseNet ( ) [inline]

Definition at line 117 of file Core.h.

{ return RestoreCloseNet(PR_FALSE); };
nsresult Core::ConflictResolveUI ( PRBool  download,
const nsCStringArray &  files,
nsCStringArray *  result 
)

Definition at line 167 of file Core.cpp.

{
  if (files.Count() < 1)
    return NS_OK;

  /* nsIDialogParamBlock is a method to pass ints and strings
     to and from XUL dialogs.
     To dialog (upon open)
       Int array
         Item 0: 1 = download, 2 = upload
         Item 1: Number of files (n below)
       String array
         Item 1..(n): Either filename or comma-separated (no spaces) string:
                      - filename
                      - last modified (unix time) server
                      - size (bytes) server
                      - last modified (unix time) local
                      - size (bytes) local
                      e.g. "bookmarks.html,100024563,325,100024535,245" or
                      "bookmarks.html"
     From dialog (upon close)
       Int array
         Item 0:      3 = OK, 4 = Cancel
         Item 1..(n): if OK:
                      1 = Use server version, 2 = Use local version.
                      For each file. Indices are the same as To/String
  */
  nsresult rv;

  nsCOMPtr<nsIDialogParamBlock> ioParamBlock
             (do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1", &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  // download/upload
  ioParamBlock->SetInt(0, download ? 1 : 2);

  // filenames
  ioParamBlock->SetInt(1, files.Count());
  PRInt32 i;
  for (i = files.Count() - 1; i >= 0; i--)
  {
    NS_ConvertASCIItoUTF16 filename(*files.CStringAt(i));
    ioParamBlock->SetString(i + 1, filename.get());
  }

  nsCOMPtr<nsIWindowWatcher> windowWatcher
                             (do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIDOMWindow> window;
  rv = windowWatcher->OpenWindow(nsnull,
                                 kConflDlg,
                                 nsnull,
                                 "centerscreen,chrome,modal,titlebar",
                                 ioParamBlock,
                                 getter_AddRefs(window));
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 value = 0;
  ioParamBlock->GetInt(0, &value);
  if (value != 3 && value != 4)
    return NS_ERROR_INVALID_ARG;
  if (value == 4) // cancel
  {
    return NS_ERROR_ABORT;
  }

  /* I am assuming that the sequence of iteration here is the same as in the
     last |for| statement. If that is not true, the indices gotten from
     param block will not match the array and we will interpret the result
     wrongly. */
  for (i = files.Count() - 1; i >= 0; i--)
  {
    ioParamBlock->GetInt(i + 1, &value);
    if (value != 1 && value != 2)
      return NS_ERROR_INVALID_ARG;
    if (download
        ? value == 1
        : value == 2)
      result->AppendCString(*files.CStringAt(i));
  }

  //*result = files;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 365 of file Core.cpp.

{
  if (mMethod == 1)
    return new Stream;
  else if (mMethod == 2)
    return new Copy;

  return 0;
}

Here is the call graph for this function:

const nsCStringArray* Core::GetFilesToRoam ( ) [inline]

Definition at line 80 of file Core.h.

{ return &mFiles; };

Here is the caller graph for this function:

PRInt32 Core::GetMethod ( ) [inline]

Definition at line 87 of file Core.h.

{ return mMethod; };

Definition at line 161 of file Core.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 254 of file Core.cpp.

{
  if (mRegistry)
  {
    result = mRegistry;
    return NS_OK;
  }

  nsresult rv;
  nsCOMPtr<nsIRegistry> registry(do_CreateInstance(NS_REGISTRY_CONTRACTID,
                                                   &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry);
  NS_ENSURE_SUCCESS(rv, rv);

  mRegistry = registry;
  result = registry;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 275 of file Core.cpp.

{
  nsRegistryKey regkey = 0;

  nsresult rv;
  nsCOMPtr<nsIProfile> profMan(do_GetService(NS_PROFILE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLString profile;
  rv = profMan->GetCurrentProfile(getter_Copies(profile));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIRegistry> registry;
  rv = GetRegistry(registry);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = registry->GetKey(nsIRegistry::Common,
                        kRegTreeProfile.get(),
                        &regkey);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = registry->GetKey(regkey,
                        profile.get(),
                        &regkey);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = registry->GetKey(regkey,
                        kRegTreeRoaming.get(),
                        &regkey);
  NS_ENSURE_SUCCESS(rv, rv);

  result = regkey;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 76 of file Core.h.

{ return mIsRoaming; };

Definition at line 315 of file Core.cpp.

{
  nsCOMPtr<nsIRegistry> registry;
  nsresult rv = GetRegistry(registry);
  NS_ENSURE_SUCCESS(rv, rv);

  nsRegistryKey regkey;
  rv = GetRegistryTree(regkey);
  if (NS_FAILED(rv)) // expected, if roaming not set up for this profile
    mIsRoaming = PR_FALSE;
  else
  {
    PRInt32 enabled;
    rv = registry->GetInt(regkey, kRegKeyEnabled.get(),
                          &enabled);
    if (NS_FAILED(rv))
    {
      mIsRoaming = PR_FALSE;
      return rv;
    }
    mIsRoaming = (enabled != 0);
  }

  if (!mIsRoaming)
    return NS_OK;

  // Method
  nsXPIDLString proto;
  rv = registry->GetString(regkey, kRegKeyMethod.get(),
                           getter_Copies(proto));
  NS_ENSURE_SUCCESS(rv, rv);
  if (proto == kRegValMethodStream)
    mMethod = 1;
  else if (proto == kRegValMethodCopy)
    mMethod = 2;

  // Files
  nsXPIDLString files_reg;
  rv = registry->GetString(regkey, kRegKeyFiles.get(),
                           getter_Copies(files_reg));
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ConvertUTF16toUTF8 files_pref(files_reg);

  mFiles.Clear();
  mFiles.ParseString(files_pref.get(), ",");

  return NS_OK;
}

Here is the call graph for this function:

nsresult Core::RestoreCloseNet ( PRBool  restore) [protected]

Definition at line 382 of file Core.cpp.

{
  const char* topic = restore ? "profile-change-net-restore"
                              : "profile-change-net-teardown";
  nsresult rv;
  nsCOMPtr<nsIObserverService> observerService
                       (do_GetService("@mozilla.org/observer-service;1", &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISupports> subject(do_GetService(NS_PROFILE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = observerService->NotifyObservers(subject, topic,
                                        NS_LITERAL_STRING("switch").get());
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Core::RestoreNet ( ) [inline]

Definition at line 116 of file Core.h.

{ return RestoreCloseNet(PR_TRUE); };

Here is the call graph for this function:


Member Data Documentation

nsCStringArray Core::mFiles [protected]

Definition at line 123 of file Core.h.

PRBool Core::mIsRoaming [protected]

Definition at line 117 of file Core.h.

PRInt32 Core::mMethod [protected]

Definition at line 122 of file Core.h.

Definition at line 126 of file Core.h.


The documentation for this class was generated from the following files: