Exemplo n.º 1
0
void SjMyMusicModule::DoneConfigPage(wxWindow* configPage__, int doneAction__)
{
	SjMyMusicConfigPage* configPage = (SjMyMusicConfigPage*)configPage__;

	// apply/cancel this module
	if( configPage->m_idxChanged )
	{
		g_mainFrame->UpdateIndex(SjDialog::FindTopLevel(configPage), FALSE);
	}

	// apply/cancel all embedded modules
	int moduleIndex = 1;
	for( int type=0; type<=1; type++ )
	{
		SjModuleList* moduleList = g_mainFrame->m_moduleSystem.GetModules(type==0? SJ_MODULETYPE_COL : SJ_MODULETYPE_COMMON);
		SjModuleList::Node* moduleNode = moduleList->GetFirst();
		while( moduleNode )
		{
			SjCommonModule* commonModule = (SjCommonModule*)moduleNode->GetData();
			if( commonModule->EmbedTo() == SJ_EMBED_TO_MUSICLIB )
			{
				wxWindow* commonPage = configPage->m_notebook->GetPage(moduleIndex);
				if( commonPage )
				{
					commonModule->DoneConfigPage(commonPage, doneAction__);
				}
				moduleIndex++;
			}

			// next
			moduleNode = moduleNode->GetNext();
		}
	}
}
Exemplo n.º 2
0
bool SjInterfaceBase::IsModuleAdded(SjModuleList& list,
                                    const wxString& file, int fileIndex, const wxString& name)
{
	SjModuleList::Node* currModuleNode = list.GetFirst();
	while( currModuleNode )
	{
		SjModule* currModule = currModuleNode->GetData();
		wxASSERT(currModule);

		if( currModule->m_interface == this )
		{
			if( currModule->m_file.CmpNoCase(file)==0
			        && currModule->m_fileIndex == fileIndex )
			{
				return TRUE;
			}

			if( currModule->m_name == name )
			{
				/*wxLogWarning("The Modules \"%s\" and \"%s\" seems to be identical." n/t,
				    currModule->m_file.c_str(), file.c_str());
				*/
				return TRUE;
			}
		}

		// next
		currModuleNode = currModuleNode->GetNext();
	}

	return FALSE;
}
Exemplo n.º 3
0
void SjMyMusicConfigPage::OnAddSources(wxCommandEvent& event)
{
	SjModuleList* list = g_mainFrame->m_moduleSystem.GetModules(SJ_MODULETYPE_SCANNER);
	wxASSERT(list);

	// find the correct module
	SjModuleList::Node* moduleNode = list->GetFirst();
	SjScannerModule*    scannerModule = NULL;
	int                 typeCount = 0, typeIndex = -1;
	while( moduleNode && typeIndex == -1 )
	{
		scannerModule = (SjScannerModule*)moduleNode->GetData();
		wxASSERT(scannerModule);
		wxASSERT(scannerModule->IsLoaded());

		size_t i;
		for( i = 0; i < scannerModule->m_addSourceTypes_.GetCount(); i++ )
		{
			if( IDC_MODULE00+typeCount == event.GetId() )
			{
				typeIndex = i; // exit outer loop
				break;
			}

			typeCount++;
		}

		// next
		moduleNode = moduleNode->GetNext();
	}

	// add by module
	if( typeIndex != -1 && scannerModule )
	{
		long newIndex;

		{
			wxWindow* topLevelWindow = SjDialog::FindTopLevel(this);
			SJ_WINDOW_DISABLER(topLevelWindow);
			newIndex = scannerModule->AddSources(typeIndex, topLevelWindow);
		}

		if( newIndex != -1 )
		{
			InitPage(scannerModule->GetSourceUrl(newIndex));
			m_idxChanged = TRUE;
			UpdateButtons();
		}
	}
}
Exemplo n.º 4
0
SjMyMusicConfigPage::SjMyMusicConfigPage(SjMyMusicModule* myMusicModule, wxWindow* parent, int selectedPage)
	: wxPanel(parent)
{
	// save given objects
	m_idxChanged        = FALSE;
	m_configMenuButton  = NULL;
	m_addButton         = NULL;
	m_removeButton      = NULL;
	m_currSortCol       = 0;

	// init dialog
	wxSizer* dialogSizer = new wxBoxSizer(wxVERTICAL);
	SetSizer(dialogSizer);

	m_notebook = new wxNotebook(this, IDC_NOTEBOOK, wxDefaultPosition, wxDefaultSize, 0/*wxCLIP_CHILDREN - problems with wxChoice/wxComboBox*/);
	wxNotebook* notebookSizer = m_notebook;

	m_notebook->AddPage(CreatePage(m_notebook),  _("Music library"));

	for( int type=0; type<=1; type++ )
	{
		SjModuleList* moduleList = g_mainFrame->m_moduleSystem.GetModules(type==0? SJ_MODULETYPE_COL : SJ_MODULETYPE_COMMON);
		SjModuleList::Node* moduleNode = moduleList->GetFirst();
		while( moduleNode )
		{
			SjCommonModule* commonModule = (SjCommonModule*)moduleNode->GetData();
			if( commonModule->EmbedTo() == SJ_EMBED_TO_MUSICLIB )
			{
				m_notebook->AddPage(commonModule->GetConfigPage(m_notebook, 0), commonModule->m_name);
			}

			moduleNode = moduleNode->GetNext();
		}
	}

	if( selectedPage < 0
	 || selectedPage >= (int)m_notebook->GetPageCount() )
	{
		selectedPage = 0;
	}

	m_notebook->SetSelection(selectedPage);

	dialogSizer->Add(notebookSizer, 1, wxALL|wxGROW, SJ_DLG_SPACE);

	dialogSizer->SetSizeHints(this);

	// init data
	InitPage(g_tools->m_config->Read("settings/selSource", ""));
}
Exemplo n.º 5
0
void SjModuleSystem::BroadcastMsg(int msg)
{
	static int inSendMsg = 0;

	wxASSERT( wxThread::IsMain() );
	wxASSERT( msg!=0 );

	if( inSendMsg == msg )
	{
		wxLogError("Recursive call of SjModuleSystem::SendMsg (msg=%i)."/*n/t*/, (int)msg);
	}
	else
	{
		inSendMsg = msg;

		// send message to all interfaces
		#if 0
		SjInterfaceList::Node* interfaceNode = m_listOfInterfaces.GetFirst();
		while( interfaceNode )
		{
			SjInterfaceBase* interf = interfaceNode->GetData();
			wxASSERT(interf);

			interf->ReceiveMsg(msg);

			interfaceNode = interfaceNode->GetNext();
		}
		#endif

		// send message to all modules
		SjModuleList::Node* moduleNode = m_listOfModules.GetFirst();
		while( moduleNode )
		{
			SjModule* module = moduleNode->GetData();
			wxASSERT(module);
			wxASSERT(module->GetUsage() >= 0);

			if( module->IsLoaded() )
			{
				module->ReceiveMsg(msg);
			}

			moduleNode = moduleNode->GetNext();
		}

		inSendMsg = 0;
	}
}
Exemplo n.º 6
0
void SjModuleSystem::LoadModules()
{
	// This function may only be called from the main thread.
	#ifdef __WXDEBUG__
		wxASSERT( wxThread::IsMain() );
		static bool s_functionCalled = false;
		wxASSERT( !s_functionCalled );
		s_functionCalled = true;
	#endif

	// get modules
	SjInterfaceList::Node* interfaceNode = m_listOfInterfaces.GetFirst();
	while( interfaceNode )
	{
		SjInterfaceBase* interf = interfaceNode->GetData();
		wxASSERT(interf);

		// get the modules from the interface
		interf->LoadModules(m_listOfModules);

		// continue with next interface
		interfaceNode = interfaceNode->GetNext();
	}

	m_listOfModules.Sort(SjModuleSystem_CmpModulesByAll);

	// create type lists
	int type;
	for( type = 1; type < SJ_MODULETYPE_COUNT; type++ )
	{
		m_listOfModules2[type].Clear();
		SjModuleList::Node* moduleNode = m_listOfModules.GetFirst();
		while( moduleNode )
		{
			SjModule* module = moduleNode->GetData();
			wxASSERT(module);

			if( module->m_type == type )
			{
				m_listOfModules2[type].Append(module);
			}

			moduleNode = moduleNode->GetNext();
		}
	}
}
Exemplo n.º 7
0
SjScannerModule* SjModuleSystem::FindScannerModuleByUrl(const wxString& url)
{
	SjModuleList*       scannerList = GetModules(SJ_MODULETYPE_SCANNER);
	SjModuleList::Node* scannerNode = scannerList->GetFirst();
	while( scannerNode )
	{
		SjScannerModule* scannerModule = (SjScannerModule*)scannerNode->GetData();
		wxASSERT( scannerModule );
		wxASSERT( scannerModule->IsLoaded() );

		if( scannerModule->IsMyUrl(url) )
		{
			return scannerModule;
		}

		scannerNode = scannerNode->GetNext();
	}
	return NULL;
}
Exemplo n.º 8
0
SjModule* SjModuleSystem::FindModuleByFile(const wxString& file, int fileIndex)
{
	SjModuleList*       list = GetModules(SJ_MODULETYPE_ALL);
	SjModuleList::Node* moduleNode = list->GetFirst();
	SjModule*           module;
	while( moduleNode )
	{
		module = moduleNode->GetData();
		wxASSERT(module);

		if( module->m_file.CmpNoCase(file) == 0
		        && module->m_fileIndex == fileIndex )
		{
			return module;
		}

		moduleNode = moduleNode->GetNext();
	}

	return NULL;
}
Exemplo n.º 9
0
void SjModuleSystem::UnloadPending(bool ignoreTimestamp)
{
	wxASSERT( wxThread::IsMain() );

	// physicall unload pending modules
	unsigned long thisTimestamp = SjTools::GetMsTicks();
	SjModuleList::Node* node = m_listOfPendingModules.GetFirst();
	while( node )
	{
		SjModule* m = node->GetData();

		wxASSERT( m );
		wxASSERT( m->m_pushPendingTimestamp != 0 );

		if( ignoreTimestamp
		 || SjTimestampDiff(m->m_pushPendingTimestamp, thisTimestamp) > SJ_PENDING_MODULES_MS )
		{
			m->m_pushPendingTimestamp = 0; // prepare for the next pending
			m->LastUnload();

			// also delete the module pointer itself?
			if( m->m_destroyPending )
			{
				delete m;
			}

			m_listOfPendingModules.DeleteNode(node);

			node = m_listOfPendingModules.GetFirst(); // start over
		}
		else
		{
			node = node->GetNext(); // next in list
		}
	}
}
Exemplo n.º 10
0
void SjColumnMixer::LoadModules(SjModuleSystem* moduleSystem)
{
	wxASSERT(m_moduleCount==0);
	wxASSERT(m_libraryModule==NULL);

	SjModuleList*       moduleList = moduleSystem->GetModules(SJ_MODULETYPE_COL);
	SjModuleList::Node* moduleNode = moduleList->GetFirst();
	while( moduleNode )
	{
		SjColModule* module = (SjColModule*)moduleNode->GetData();
		wxASSERT(module);

		if( module->Load() )
		{
			if( module->m_file == wxT("memory:library.lib") )
			{
				m_libraryModule = module;
			}

			m_modules[m_moduleCount] = module;
			m_moduleMaskedColCount[m_moduleCount] = -1;
			m_moduleUnmaskedColCount[m_moduleCount] = -1;
			m_moduleCount++;

			if( m_moduleCount>=SJ_COLUNMMIXER_MAX_MODULES )
			{
				wxLogError(wxT("Too many column modules."));
				break; // out of while
			}
		}

		moduleNode = moduleNode->GetNext();
	}

	SetColCount__();
}
Exemplo n.º 11
0
void SjModuleSystem::Exit()
{
	int i;

	// unload all scripts
	#if SJ_USE_SCRIPTS
	for( i = 0; i < (int)m_sees.GetCount(); i++ )
	{
		SjSee* see = (SjSee*)m_sees[i];
		delete see;
	}
	m_sees.Empty();
	#endif

	// unload all modules -- we do this in two steps: first the plugins, then the internal modules
	SjModuleList::Node* moduleNode;
	for( i = 0; i < 2; i++ )
	{
		moduleNode = m_listOfModules.GetFirst();
		while( moduleNode )
		{
			SjModule* module = moduleNode->GetData();
			wxASSERT(module);

			if( (i==0 && module->m_interface != g_internalInterface)
			        || (i==1 && module->m_interface == g_internalInterface) )
			{
				long iteration = 0;
				while( module->IsLoaded() && iteration < 100 )
				{
					module->Unload();
					iteration++;
				}
				wxASSERT( !module->IsLoaded() );
			}

			// next module
			moduleNode = moduleNode->GetNext();
		}
	}

	UnloadPending(TRUE /*ignoreTimeouts*/);
	wxASSERT( m_listOfPendingModules.GetCount() == 0 );

	// delete all modules, should be done after unloading as
	// some modules keep pointers to other loaded modules
	moduleNode = m_listOfModules.GetFirst();
	while( moduleNode )
	{
		delete moduleNode->GetData();
		delete moduleNode;
		moduleNode = m_listOfModules.GetFirst();
	}

	// delete all module interfaces
	SjInterfaceList::Node* interfaceNode = m_listOfInterfaces.GetFirst();
	while( interfaceNode )
	{
		SjInterfaceBase* interf = interfaceNode->GetData();
		wxASSERT(interf);

		// next module
		delete interf;
		delete interfaceNode;
		interfaceNode = m_listOfInterfaces.GetFirst();
	}
	m_listOfInterfaces.Clear();

	// delete module lists
	for( i = 0; i < SJ_MODULETYPE_COUNT; i++ )
	{
		m_listOfModules2[i].Clear();
	}

	m_hashOfExt.Clear();

	// exit database
	wxSqltDb* db = wxSqltDb::GetDefault();
	if( db )
	{
		// NULL the pointer (the default database);
		// real deletion is done after ::GcShutdown() in SjMainApp
		// (this is needed as
		wxSqltDb::ClearDefault();
		s_delayedDbDelete = db;
	}
}
Exemplo n.º 12
0
void SjMyMusicConfigPage::ShowContextMenu(wxWindow* window, const wxPoint& pt)
{
	SjMenu                  m(0);
	SjSettingsSourceItem*   source = GetSelFromDialog(); // may be NULL!

	if( window == this || window == m_addButton )
	{
		SjModuleList* list = g_mainFrame->m_moduleSystem.GetModules(SJ_MODULETYPE_SCANNER);
		wxASSERT(list);

		SjModuleList::Node* moduleNode = list->GetFirst();
		SjScannerModule*    scannerModule;
		int                 typeCount = 0;

		while( moduleNode )
		{
			scannerModule = (SjScannerModule*)moduleNode->GetData();
			wxASSERT(scannerModule);
			wxASSERT(scannerModule->IsLoaded());

			size_t i;
			wxASSERT( scannerModule->m_addSourceTypes_.GetCount() == scannerModule->m_addSourceIcons_.GetCount() );
			for( i = 0; i < scannerModule->m_addSourceTypes_.GetCount(); i++ )
			{
				m.Append(IDC_MODULE00+typeCount, scannerModule->m_addSourceTypes_.Item(i)+"...");

				typeCount++;
			}

			// next
			moduleNode = moduleNode->GetNext();
		}
	}

	if( window == this )
	{
		m.Append(IDC_IDXDELSOURCE, _("Remove source"));
		m.Enable(IDC_IDXDELSOURCE, source!=NULL);
	}

	if( window == this || window == m_configMenuButton )
	{
		if( m.GetMenuItemCount() )
		{
			m.AppendSeparator();
		}

		if( source )
		{
			m.Append(IDC_IDXCONFIGSOURCE, wxString::Format(_("Options for \"%s\""), SjTools::ShortenUrl(source->GetUrl()).c_str())+"...");
		}
		else
		{
			m.Append(IDC_IDXCONFIGSOURCE, _("Options..."));
			m.Enable(IDC_IDXCONFIGSOURCE, FALSE);
		}

		m.Append(IDM_EXPLORE);
		m.Enable(IDM_EXPLORE, source!=NULL);
	}

	if( window == this || window == m_updateButton )
	{
		if( m.GetMenuItemCount() )
		{
			m.AppendSeparator();
		}

		m.Append(IDT_UPDATE_INDEX);
		m.Append(IDT_DEEP_UPDATE_INDEX);
	}

	window->PopupMenu(&m, pt);
}
Exemplo n.º 13
0
void SjMyMusicConfigPage::InitPage(const wxString& selSourceUrl)
{
	// create index list
	m_listOfSources.Clear();
	m_listOfSources.DeleteContents(TRUE);

	SjModuleList* list = g_mainFrame->m_moduleSystem.GetModules(SJ_MODULETYPE_SCANNER);
	wxASSERT(list);

	SjModuleList::Node* moduleNode = list->GetFirst();
	SjScannerModule*    scannerModule;
	while( moduleNode )
	{
		scannerModule = (SjScannerModule*)moduleNode->GetData();
		wxASSERT(scannerModule);
		wxASSERT(scannerModule->IsLoaded());

		long sourceCount = scannerModule->GetSourceCount();
		long currSourceIndex;
		for( currSourceIndex = 0; currSourceIndex < sourceCount; currSourceIndex++ )
		{
			SjSettingsSourceItem* item = new SjSettingsSourceItem(scannerModule, currSourceIndex, scannerModule->GetSourceUrl(currSourceIndex), scannerModule->GetSourceIcon(currSourceIndex));
			m_listOfSources.Append(item);
		}

		// next
		moduleNode = moduleNode->GetNext();
	}

	// get list control
	m_listCtrl->Freeze();
	m_listCtrl->DeleteAllItems();

	// go through all search directories
	SjSettingsSourceItem*           item;
	SjSettingsSourceItemList::Node* itemnode = m_listOfSources.GetFirst();
	int                             i = 0;
	wxString                        sourceNotes;
	while( itemnode )
	{
		item = itemnode->GetData();
		wxASSERT(item);

		wxListItem listitem;
		listitem.m_mask     = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT | wxLIST_MASK_DATA;
		listitem.m_itemId   = i;
		listitem.m_text     = item->GetUrl();
		listitem.SetData((void*)item);
		listitem.m_image    = item->GetScannerModule()->GetSourceIcon(item->GetIndex());

		sourceNotes = item->GetScannerModule()->GetSourceNotes(item->GetIndex());
		if( !sourceNotes.IsEmpty() )
		{
			listitem.m_text.Append(" (");
			listitem.m_text.Append(sourceNotes);
			listitem.m_text.Append(')');
		}

		m_listCtrl->InsertItem(listitem);

		itemnode = itemnode->GetNext();
		i++;
	}

	m_listCtrl->SortItems(ListCtrlCompareFunction, m_currSortCol);

	m_listCtrl->Thaw();

	// select the correct item
	// (should be done after SortItems() on GTK this may remove the selection ...)
	int i_cnt = m_listCtrl->GetItemCount();
	for( i = 0; i < i_cnt; i ++ )
	{
		item = (SjSettingsSourceItem*)m_listCtrl->GetItemData(i);
		if( item->GetUrl() == selSourceUrl ) {
			m_listCtrl->SetItemState(i, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
			break;
		}
	}

	UpdateButtons();
}