Example #1
0
CFStringRef	HLFileSystemObject::CopyDisplayName() const
{
	//	get the display name from Launch Services
	CFStringRef theDisplayName = NULL;
	OSStatus theError = LSCopyDisplayNameForRef(&mFSRef, &theDisplayName);
	ThrowIfError(theError, CAException(theError), "HLFileSystemObject::CopyDisplayName: couldn't get the display name");
	
	return theDisplayName;
}
Example #2
0
static PyObject *Launch_LSCopyDisplayNameForRef(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    OSStatus _err;
    FSRef inRef;
    CFStringRef outDisplayName;
    if (!PyArg_ParseTuple(_args, "O&",
                          PyMac_GetFSRef, &inRef))
        return NULL;
    _err = LSCopyDisplayNameForRef(&inRef,
                                   &outDisplayName);
    if (_err != noErr) return PyMac_Error(_err);
    _res = Py_BuildValue("O&",
                         CFStringRefObj_New, outDisplayName);
    return _res;
}
Example #3
0
QString QDesktopServices::displayName(StandardLocation type)
{
    if (QDesktopServices::HomeLocation == type)
        return QObject::tr("Home");

    FSRef ref;
    OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref);
    if (err)
        return QString();

    QCFString displayName;
    err = LSCopyDisplayNameForRef(&ref, &displayName);
    if (err)
        return QString();

    return static_cast<QString>(displayName);
}
Example #4
0
QString QStandardPaths::displayName(StandardLocation type)
{
    if (QStandardPaths::HomeLocation == type)
        return QCoreApplication::translate("QStandardPaths", "Home");

    FSRef ref;
    OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref);
    if (err)
        return QString();

    CFStringRef displayName = 0;
    err = LSCopyDisplayNameForRef(&ref, &displayName);
    if (err)
        return QString();

    QString result = QString::fromUtf16((ushort*)CFStringGetCharactersPtr(displayName), CFStringGetLength(displayName));
    CFRelease(displayName);
    return result;
}
Example #5
0
void RequestMidiFilename(std::wstring *returned_filename, std::wstring *returned_file_title)
{
   // Grab the filename of the last song we played
   // and pre-load it into the open dialog
   wstring last_filename = UserSetting::Get(L"Last File", L"");

   const static int BufferSize = 512;
   wchar_t filename[BufferSize] = L"";
   wchar_t filetitle[BufferSize] = L"";

#ifdef WIN32
   // Try to populate our "File Open" box with the last file selected
   if (StringCbCopyW(filename, BufferSize, last_filename.c_str()) == STRSAFE_E_INSUFFICIENT_BUFFER)
   {
      // If there wasn't a last file, default to the built-in Music directory
      filename[0] = L'\0';
   }

   wstring default_dir;
   bool default_directory = false;
   if (last_filename.length() == 0)
   {
      default_directory = true;
      default_dir = UserSetting::Get(L"Default Music Directory", L"");

      if (!SetCurrentDirectory(default_dir.c_str()))
      {
         // LOGTODO!
         // This is non-critical.  No action required.
      }
   }

   OPENFILENAME ofn;
   ZeroMemory(&ofn, sizeof(OPENFILENAME));
   ofn.lStructSize =     sizeof(OPENFILENAME);
   ofn.hwndOwner =       0;
   ofn.lpstrTitle =      L"Piano Game: Choose a MIDI song to play";
   ofn.lpstrFilter =     L"MIDI Files (*.mid)\0*.mid;*.midi\0All Files (*.*)\0*.*\0";
   ofn.lpstrFile =       filename;
   ofn.nMaxFile =        BufferSize;
   ofn.lpstrFileTitle =  filetitle;
   ofn.lpstrInitialDir = default_dir.c_str();
   ofn.nMaxFileTitle =   BufferSize;
   ofn.lpstrDefExt =     L"mid";
   ofn.Flags =           OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;

   if (GetOpenFileName(&ofn))
   {
      std::wstring filename = WSTRING(ofn.lpstrFile);

      SetLastMidiFilename(filename);

      if (returned_file_title) *returned_file_title = WSTRING(filetitle);
      if (returned_filename) *returned_filename = filename;
      return;
   }

   if (returned_file_title) *returned_file_title = L"";
   if (returned_filename) *returned_filename = L"";

#else
   
   OSStatus status;
   
   NavDialogCreationOptions options;
   status  = NavGetDefaultDialogCreationOptions(&options);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create dialog options.  Error code: " << static_cast<int>(status)));
   
   options.windowTitle = CFSTR("Piano Game: Choose a MIDI song to play");
   
   // TODO: Should clean this up at shut-down
   static NavObjectFilterUPP navFilterUPP(0);
   if (navFilterUPP == 0) navFilterUPP = NewNavObjectFilterUPP(NavOpenFilterProc);
   
   NavDialogRef navDialog(0);
   status = NavCreateChooseFileDialog(&options, 0, 0, 0, navFilterUPP, 0, &navDialog);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create open dialog.  Error code: " << static_cast<int>(status)));
   
   status = NavDialogRun(navDialog);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't run open dialog.  Error code: " << static_cast<int>(status)));
   
   NavReplyRecord navReply;
   status = NavDialogGetReply(navDialog, &navReply);

   if (status == userCanceledErr || !navReply.validRecord)
   {
      NavDisposeReply(&navReply);

      if (returned_file_title) *returned_file_title = L"";
      if (returned_filename) *returned_filename = L"";
      return;
   }
   
   long item_count = 0;
   status = AECountItems(&navReply.selection, &item_count);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't count resulting items from open dialog.  Error code: " << static_cast<int>(status)));
      
   for (long i = 1; i <= item_count; i++)
   {
      FSRef fsRef;
      status = AEGetNthPtr(&navReply.selection, i, typeFSRef, 0, 0, &fsRef, sizeof(FSRef), 0);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get FSRef pointer from open dialog.  Error code: " << static_cast<int>(status)));

      CFStringRef file_title;
      status = LSCopyDisplayNameForRef( &fsRef, &file_title );
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get file title.  Error code: " << static_cast<int>(status)));
      
      const static int BufferSize(1024);
      char path_buffer[BufferSize];
      status = FSRefMakePath(&fsRef, (UInt8*)path_buffer, BufferSize);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get file path.  Error code: " << static_cast<int>(status)));
      
      std::string narrow_path(path_buffer);
      std::wstring filepath(narrow_path.begin(), narrow_path.end());
      
      if (returned_file_title) *returned_file_title = WideFromMacString(file_title);
      if (returned_filename) *returned_filename = filepath;
      
      CFRelease(file_title);
   }
   
   NavDisposeReply(&navReply);
   
#endif
}